Share blob size loading code
[gitphp.git] / include / git / blob / BlobLoad_Git.class.php
blob:a/include/git/blob/BlobLoad_Git.class.php -> blob:b/include/git/blob/BlobLoad_Git.class.php
<?php <?php
/** /**
* Blob load strategy using git exe * Blob load strategy using git exe
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2012 Christopher Han * @copyright Copyright (c) 2012 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Git\Blob * @subpackage Git\Blob
*/ */
class GitPHP_BlobLoad_Git implements GitPHP_BlobLoadStrategy_Interface class GitPHP_BlobLoad_Git extends GitPHP_BlobLoad_Base
{ {
/**  
* Executable  
*  
* @var GitPHP_GitExe  
*/  
protected $exe;  
   
/**  
* Constructor  
*  
* @param GitPHP_GitExe $exe executable  
*/  
public function __construct($exe)  
{  
if (!$exe)  
throw new Exception('Git exe is required');  
   
$this->exe = $exe;  
}  
   
/** /**
* Gets the data for a blob * Gets the data for a blob
* *
* @param GitPHP_Blob $blob blob * @param GitPHP_Blob $blob blob
* @return string blob data * @return string blob data
*/ */
public function Load($blob) public function Load($blob)
{ {
if (!$blob) if (!$blob)
return; return;
   
$args = array(); $args = array();
$args[] = 'blob'; $args[] = 'blob';
$args[] = $blob->GetHash(); $args[] = $blob->GetHash();
   
return $this->exe->Execute($blob->GetProject()->GetPath(), GIT_CAT_FILE, $args); return $this->exe->Execute($blob->GetProject()->GetPath(), GIT_CAT_FILE, $args);
} }
   
/** /**
* Gets the size of a blob * Gets the size of a blob
* *
* @param GitPHP_Blob $blob blob * @param GitPHP_Blob $blob blob
* @return int blob size * @return int blob size
*/ */
public function Size($blob) public function Size($blob)
{ {
if (!$blob) return $this->LoadSize($blob);
return;  
   
$args = array();  
$args[] = '-s';  
$args[] = $blob->GetHash();  
   
return $this->exe->Execute($blob->GetProject()->GetPath(), GIT_CAT_FILE, $args);  
} }
} }
   
comments