예제 #1
0
 /**
  * Gets a blob
  *
  * @param string $hash blob hash
  * @return GitPHP_Blob blob object
  */
 public function GetBlob($hash)
 {
     if (empty($hash)) {
         return null;
     }
     if (preg_match('/^[0-9A-Fa-f]{4,39}$/', $hash) && !$this->compat) {
         $fullHash = $this->project->ExpandHash($hash);
         if ($fullHash == $hash) {
             throw new GitPHP_InvalidHashException($hash);
         }
         $hash = $fullHash;
     }
     if (!preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) {
         return null;
     }
     $key = GitPHP_Blob::CacheKey($this->project->GetProject(), $hash);
     $blob = null;
     if ($this->memoryCache) {
         $blob = $this->memoryCache->Get($key);
     }
     if (!$blob) {
         if ($this->cache) {
             $blob = $this->cache->Get($key);
         }
         $strategy = null;
         if ($this->compat) {
             $strategy = new GitPHP_BlobLoad_Git($this->exe);
         } else {
             $strategy = new GitPHP_BlobLoad_Raw($this->objectLoader, $this->exe);
         }
         if ($blob) {
             $blob->SetProject($this->project);
             $blob->SetStrategy($strategy);
         } else {
             $blob = new GitPHP_Blob($this->project, $hash, $strategy);
         }
         $blob->AddObserver($this);
         if ($this->memoryCache) {
             $this->memoryCache->Set($key, $blob);
         }
     }
     return $blob;
 }
예제 #2
0
 /**
  * Gets the cache key to use for this object
  *
  * @return string cache key
  */
 public function GetCacheKey()
 {
     return GitPHP_Blob::CacheKey($this->project->GetProject(), $this->hash);
 }