示例#1
0
 public function addToArchive(Archive_Tar $archive)
 {
     $rval = $archive->addModify($this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath(), null, $this->getBasePath());
     if ($archive->isError($rval)) {
         throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage());
     }
 }
 public static function inflate($file, $outputPath)
 {
     // Sanity
     if (!file_exists($file) || !is_file($file) || strtolower(pathinfo($file, PATHINFO_EXTENSION)) != 'tar') {
         throw new Engine_Package_Exception('File does not exist or is not a tar file');
     }
     if (!file_exists($outputPath) || !is_dir($outputPath) || !is_writeable($outputPath)) {
         throw new Engine_Package_Exception('Output path does not exist, is not a directory, or is not writeable');
     }
     self::_loadArchiveClass();
     // Make other paths
     $outputSubPath = substr(basename($file), 0, strrpos(basename($file), '.'));
     $outputFullPath = rtrim($outputPath, '/\\') . DIRECTORY_SEPARATOR . $outputSubPath;
     // If output path already exists, remove
     if (file_exists($outputFullPath)) {
         self::_rmdirRecursive($outputFullPath, true);
     }
     // Try to make full output path
     if (!is_dir($outputFullPath)) {
         if (!mkdir($outputFullPath, 0777, true)) {
             throw new Engine_Package_Exception('Unable to create output folder');
         }
     }
     // Extract
     $archive = new Archive_Tar($file);
     $rval = $archive->extract($outputFullPath);
     // Throw error if failed
     if ($archive->isError($rval)) {
         throw new Engine_Package_Exception('Error in archive: ' . $rval->getMessage());
     }
     return $outputFullPath;
 }
 public function addToArchive(Archive_Tar $archive)
 {
     // Add package file
     $rval = $archive->addString('application' . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . $this->getKey() . '.json', $this->toString('json'));
     if ($archive->isError($rval)) {
         throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage());
     }
     // Add internal structure
     if ($this->getAddDirectoryToArchive()) {
         $rval = $archive->addModify($this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath(), null, $this->getBasePath());
         if ($archive->isError($rval)) {
             throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage());
         }
     } else {
         foreach ($this->getStructure() as $key => $value) {
             if ($this->_jitInstantiation && is_array($value) && !empty($value['type'])) {
                 $class = 'Engine_Package_Manifest_Entity_' . ucfirst($value['type']);
                 Engine_Loader::loadClass($class);
                 $value = new $class($value);
                 $value->setBasePath($this->getBasePath());
             } else {
                 if (!$value instanceof Engine_Package_Manifest_Entity_Abstract) {
                     throw new Engine_Package_Manifest_Exception('Not a package entity');
                 }
             }
             if (method_exists($value, 'setAddDirectoryToArchive')) {
                 $value->setAddDirectoryToArchive($this->getAddDirectoryToArchive());
             }
             $value->addToArchive($archive);
         }
     }
 }
示例#4
0
 public function addToArchive(Archive_Tar $archive)
 {
     if ($this->getAddDirectoryToArchive()) {
         $rval = $archive->addModify($this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath(), null, $this->getBasePath());
         if ($archive->isError($rval)) {
             throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage());
         }
     } else {
         foreach ($this->getStructure() as $key => $value) {
             $fullpath = $this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath() . DIRECTORY_SEPARATOR . $value['path'];
             if (is_dir($fullpath)) {
                 continue;
             }
             $rval = $archive->addModify($fullpath, null, $this->getBasePath());
             if ($archive->isError($rval)) {
                 throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage());
             }
         }
     }
 }