예제 #1
0
 /**
  * zipFiles
  *
  * @param SplFileInfo $file
  * @param SplFileInfo $sqlFile
  *
  * @return bool
  */
 protected function zipFiles(\SplFileInfo $file, \SplFileInfo $sqlFile)
 {
     // Delete old file
     if (is_file($file->getPathname())) {
         @unlink($file->getPathname());
     }
     $zip = new ZipArchive();
     if ($zip->open($file->getPathname(), ZipArchive::CREATE) === true) {
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getOption('root'), RecursiveDirectoryIterator::SKIP_DOTS));
         $filter = new FileFilter($this->getOption('ignores'), $this->getOption('root'));
         /** @var \SplFileInfo $item */
         foreach ($iterator as $item) {
             // Excludes
             if ($filter->test($item->getPathname())) {
                 continue;
             }
             $dest = str_replace($this->getOption('root') . DIRECTORY_SEPARATOR, '', $item->getPathname());
             if ($item->isDir()) {
                 $zip->addEmptyDir($dest);
                 continue;
             }
             $zip->addFile($item->getPathname(), $dest);
         }
         if ($this->getOption('dump_database', true)) {
             $zip->addFile($sqlFile->getPathname(), $sqlFile->getBasename());
         }
     }
     return $zip->close();
 }