示例#1
0
文件: entry.php 项目: bmdevel/ezc
 /**
  * Returns one or an array of ezcArchiveEntry's from one or multiple files in the file system.
  *
  * One or multiple ezcArchiveEntry's are created upon the given files.
  * The prefix will directly set for the ezcArchiveEntry with $prefix.
  *
  * If $files contains a path to a file, then one ezcArchiveEntry will be created and returned.
  * If $files is an array of paths, then all those ezcArchiveEntry's will be created and returned in an array.
  *
  * When multiple files are given in an array, this method will search for hard links among other files in the array.
  *
  * @throws ezcArchiveEntryPrefixException if the prefix is invalid.
  *
  * @param string|array(string)  $files
  * @param string                $prefix
  * @return ezcArchiveEntry
  */
 public static function getEntryFromFile($files, $prefix)
 {
     $isArray = true;
     if (!is_array($files)) {
         $isArray = false;
         $files = array($files);
     }
     $inodes = array();
     $i = 0;
     foreach ($files as $file) {
         if (!file_exists($file) && !is_link($file)) {
             return false;
         }
         $struct = self::getFileStructureFromFile($file);
         // Check if it's a hardlink if the OS supports it, and handle it.
         if (ezcBaseFeatures::supportsLink()) {
             if (isset($inodes[$struct->ino])) {
                 // Yes, it's a hardlink.
                 $struct->type = ezcArchiveEntry::IS_LINK;
                 $struct->size = 0;
                 $struct->link = $inodes[$struct->ino];
             } else {
                 $inodes[$struct->ino] = $struct->path;
             }
         }
         $entry[$i] = new ezcArchiveEntry($struct);
         $entry[$i]->setPrefix($prefix);
         if (isset($prefix) && strlen($prefix) > 0) {
             if (strlen($entry[$i]->getPath()) == strlen($entry[$i]->getPath(false))) {
                 throw new ezcArchiveEntryPrefixException($prefix, $file);
             }
         }
         $i++;
     }
     return $isArray ? $entry : $entry[0];
 }
 public function testSupportsLink()
 {
     $this->assertEquals(true, ezcBaseFeatures::supportsLink());
 }
示例#3
0
 public function testSupportsLink()
 {
     $this->assertFalse(ezcBaseFeatures::supportsLink());
 }