예제 #1
0
 public function testObserver()
 {
     $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock();
     $blob = new GitPHP_Blob($projectmock, '1234567890abcdef1234567890ABCDEF12345678', $this->getMock('GitPHP_BlobLoadStrategy_Interface'));
     $observermock = $this->getMock('GitPHP_Observer_Interface');
     $matcher = $this->once();
     $observermock->expects($matcher)->method('ObjectChanged')->with($this->isInstanceOf('GitPHP_Blob'), $this->equalTo(GitPHP_Observer_Interface::CacheableDataChange));
     $blob->AddObserver($observermock);
     $data = $blob->GetData();
     $data = $blob->GetData();
     //cached
     $this->assertEquals(1, $matcher->getInvocationCount());
 }
예제 #2
0
 /**
  * Gets the size of a blob
  *
  * @param GitPHP_Blob $blob blob
  * @return int blob size
  */
 public function Size($blob)
 {
     if (!$blob) {
         return;
     }
     if ($blob->DataLoaded()) {
         return strlen($blob->GetData());
     }
     return $this->LoadSize($blob);
 }
 /**
  * Gets the mime type for a blob
  *
  * @param GitPHP_Blob $blob blob
  * @return string mime type
  */
 public function GetMime($blob)
 {
     if (!$blob) {
         return false;
     }
     $data = $blob->GetData();
     if (empty($data)) {
         return false;
     }
     $mime = '';
     $finfo = @finfo_open(FILEINFO_MIME, $this->magicdb);
     if ($finfo) {
         $mime = finfo_buffer($finfo, $data, FILEINFO_MIME);
         if ($mime && strpos($mime, '/')) {
             if (strpos($mime, ';')) {
                 $mime = strtok($mime, ';');
             }
         }
         finfo_close($finfo);
     }
     return $mime;
 }
예제 #4
-1
 /**
  * Gets the mime type for a blob
  *
  * @param GitPHP_Blob $blob blob
  * @return string mime type
  */
 public function GetMime($blob)
 {
     if (!$blob) {
         return false;
     }
     $data = $blob->GetData();
     if (empty($data)) {
         return false;
     }
     $descspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
     $proc = proc_open('file -b --mime -', $descspec, $pipes);
     if (is_resource($proc)) {
         fwrite($pipes[0], $data);
         fclose($pipes[0]);
         $mime = stream_get_contents($pipes[1]);
         fclose($pipes[1]);
         proc_close($proc);
         if ($mime && strpos($mime, '/')) {
             if (strpos($mime, ';')) {
                 $mime = strtok($mime, ';');
             }
             return $mime;
         }
     }
     return false;
 }