/**
  * Action to download a set of files an directories in an archive
  * @param array $files The files and directories to download
  * @return null
  */
 public function archiveAction(array $files = null)
 {
     if ($files == null) {
         $this->response->setRedirect($this->getReferer());
         return;
     }
     $path = $this->fileBrowser->getPath($this->path);
     $name = $path->getName();
     if ($name == FileBrowser::DEFAULT_PATH) {
         $translator = $this->getTranslator();
         $name = $translator->translate(BrowserTable::TRANSLATION_NAVIGATION_HOME);
     }
     $name .= '.' . self::ARCHIVE_EXTENSION;
     $rootPath = Zibo::getInstance()->getRootPath();
     $archivePath = Zibo::DIRECTORY_APPLICATION . '/' . Zibo::DIRECTORY_DATA;
     $archiveFile = new File($rootPath, $archivePath . '/' . $name);
     $archiveFile = $archiveFile->getCopyFile();
     $archive = ArchiveFactory::getInstance()->getArchive($archiveFile);
     $browserRootPath = $this->fileBrowser->getRoot();
     foreach ($files as $file) {
         $file = new File($browserRootPath, $file);
         $archive->compress($file);
     }
     $this->getSession()->set(self::SESSION_DOWNLOAD, $archiveFile);
 }
 /**
  * @expectedException zibo\library\archive\exception\ArchiveException
  */
 public function testGetArchiveWithInvalidArchiveThrowsException()
 {
     $file = new File('test.txt');
     $factory = new ArchiveFactory($this->zibo);
     $factory->getArchive($file);
 }
 /**
  * @expectedException zibo\library\archive\exception\ArchiveException
  */
 public function testGetArchiveWithInvalidArchiveThrowsException()
 {
     $file = new File('test.txt');
     $factory = ArchiveFactory::getInstance();
     $factory->getArchive($file);
 }
예제 #4
0
 /**
  * Copies a file into the modules directory
  * @param zibo\library\filesystem\File $file
  * @return zibo\library\filesystem\File the destination file
  */
 private function copyFile(File $file)
 {
     if ($file->getExtension() == 'phar' && class_exists(self::CLASS_ARCHIVE_FACTORY)) {
         $module = new File(Zibo::DIRECTORY_MODULES, substr($file->getName(), 0, -5));
         $archive = ArchiveFactory::getInstance()->getArchive($file);
         $archive->uncompress($module);
     } else {
         $module = new File(Zibo::DIRECTORY_MODULES, $file->getName());
         if ($module->getAbsolutePath() != $file->getAbsolutePath()) {
             $file->copy($module);
         }
     }
     return $module;
 }