Move blob size loading to strategy
[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 implements GitPHP_BlobLoadStrategy_Interface
{ {
/** /**
* Executable * Executable
* *
* @var GitPHP_GitExe * @var GitPHP_GitExe
*/ */
protected $exe; protected $exe;
   
/** /**
* Constructor * Constructor
* *
* @param GitPHP_GitExe $exe executable * @param GitPHP_GitExe $exe executable
*/ */
public function __construct($exe) public function __construct($exe)
{ {
if (!$exe) if (!$exe)
throw new Exception('Git exe is required'); throw new Exception('Git exe is required');
   
$this->exe = $exe; $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
  *
  * @param GitPHP_Blob $blob blob
  * @return int blob size
  */
  public function Size($blob)
  {
  if (!$blob)
  return;
   
  $args = array();
  $args[] = '-s';
  $args[] = $blob->GetHash();
   
  return $this->exe->Execute($blob->GetProject()->GetPath(), GIT_CAT_FILE, $args);
  }
} }
   
comments