Don't completely replace parent GetHash, override and call base
Don't completely replace parent GetHash, override and call base

<?php <?php
/** /**
* GitPHP Ref * GitPHP Ref
* *
* Base class for ref objects * Base class for ref objects
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
   
require_once(GITPHP_GITOBJECTDIR . 'GitObject.class.php'); require_once(GITPHP_GITOBJECTDIR . 'GitObject.class.php');
   
/** /**
* Git Ref class * Git Ref class
* *
* @package GitPHP * @package GitPHP
* @subpackage Git * @subpackage Git
*/ */
abstract class GitPHP_Ref extends GitPHP_GitObject abstract class GitPHP_Ref extends GitPHP_GitObject
{ {
/** /**
* refName * refName
* *
* Stores the ref name * Stores the ref name
* *
* @access protected * @access protected
*/ */
protected $refName; protected $refName;
   
/** /**
* refDir * refDir
* *
* Stores the ref directory * Stores the ref directory
* *
* @access protected * @access protected
*/ */
protected $refDir; protected $refDir;
   
/** /**
* __construct * __construct
* *
* Instantiates ref * Instantiates ref
* *
* @access public * @access public
* @param mixed $project the project * @param mixed $project the project
* @param string $refDir the ref directory * @param string $refDir the ref directory
* @param string $refName the ref name * @param string $refName the ref name
* @param string $refHash the ref hash * @param string $refHash the ref hash
* @throws Exception if not a valid ref * @throws Exception if not a valid ref
* @return mixed git ref * @return mixed git ref
*/ */
public function __construct($project, $refDir, $refName, $refHash = '') public function __construct($project, $refDir, $refName, $refHash = '')
{ {
$this->project = $project; $this->project = $project;
$this->refDir = $refDir; $this->refDir = $refDir;
$this->refName = $refName; $this->refName = $refName;
if (!empty($refHash)) { if (!empty($refHash)) {
$this->SetHash($refHash); $this->SetHash($refHash);
} }
} }
   
/** /**
* GetHash * GetHash
* *
* Gets the hash for this ref (overrides base) * Gets the hash for this ref (overrides base)
* *
* @access public * @access public
* @return string object hash * @return string object hash
*/ */
public function GetHash() public function GetHash()
{ {
if (empty($this->hash)) if (empty($this->hash))
$this->FindHash(); $this->FindHash();
   
return $this->hash; return parent::GetHash();
} }
   
/** /**
* FindHash * FindHash
* *
* Looks up the hash for the ref * Looks up the hash for the ref
* *
* @access protected * @access protected
* @throws Exception if hash is not found * @throws Exception if hash is not found
*/ */
protected function FindHash() protected function FindHash()
{ {
$exe = new GitPHP_GitExe($this->GetProject()); $exe = new GitPHP_GitExe($this->GetProject());
$args = array(); $args = array();
$args[] = '--hash'; $args[] = '--hash';
$args[] = '--verify'; $args[] = '--verify';
$args[] = $this->GetRefPath(); $args[] = $this->GetRefPath();
$hash = trim($exe->Execute(GIT_SHOW_REF, $args)); $hash = trim($exe->Execute(GIT_SHOW_REF, $args));
   
if (empty($hash)) if (empty($hash))
throw new Exception('Invalid ref ' . $this->GetRefPath()); throw new Exception('Invalid ref ' . $this->GetRefPath());
   
$this->SetHash($hash); $this->SetHash($hash);
} }
   
/** /**
* GetName * GetName
* *
* Gets the ref name * Gets the ref name
* *
* @access public * @access public
* @return string ref name * @return string ref name
*/ */
public function GetName() public function GetName()
{ {
return $this->refName; return $this->refName;
} }
   
/** /**
* GetDirectory * GetDirectory
* *
* Gets the ref directory * Gets the ref directory
* *
* @access public * @access public
* @return string ref directory * @return string ref directory
*/ */
public function GetDirectory() public function GetDirectory()
{ {
return $this->refDir; return $this->refDir;
} }
   
/** /**
* GetRefPath * GetRefPath
* *
* Gets the path to the ref within the project * Gets the path to the ref within the project
* *
* @access public * @access public
* @return string ref path * @return string ref path
*/ */
public function GetRefPath() public function GetRefPath()
{ {
return 'refs/' . $this->refDir . '/' . $this->refName; return 'refs/' . $this->refDir . '/' . $this->refName;
} }
   
/** /**
* GetFullPath * GetFullPath
* *
* Gets the path to the ref including the project path * Gets the path to the ref including the project path
* *
* @access public * @access public
* @return string full ref path * @return string full ref path
*/ */
public function GetFullPath() public function GetFullPath()
{ {
return $this->GetProject()->GetPath() . '/' . $this->GetRefPath(); return $this->GetProject()->GetPath() . '/' . $this->GetRefPath();
} }
   
/** /**
* __sleep * __sleep
* *
* Called to prepare the object for serialization * Called to prepare the object for serialization
* *
* @access public * @access public
* @return array list of properties to serialize * @return array list of properties to serialize
*/ */
public function __sleep() public function __sleep()
{ {
$properties = array('refName', 'refDir'); $properties = array('refName', 'refDir');
   
return array_merge($properties, parent::__sleep()); return array_merge($properties, parent::__sleep());
} }
   
} }
   
comments