Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function extract($file, $path, FormatInterface $format)
 {
     if (false === $this->supportChecker->isFormatSupported($format)) {
         throw new FormatNotSupportedException($format);
     }
     $success = false;
     for ($i = 0, $methodsCount = count($this->methods); $i < $methodsCount && false === $success; $i++) {
         $method = $this->methods[$i];
         if ($method->isSupported() && $method->isFormatSupported($format)) {
             $success = $method->extract($file, $path, $format);
         }
     }
     return $success;
 }
Ejemplo n.º 2
0
 /**
  * Gets an ordered collection of preferred files.
  * @throws StrategyRequiredException
  *
  * @return FileInterface[]
  */
 public function getPreferredFilesOrdered()
 {
     if (null === $this->strategy) {
         throw new StrategyRequiredException();
     }
     $preferredFiles = $this->strategy->getPreferredFilesOrdered($this->files, $this->methods);
     if (true === $this->excludeUnsupported) {
         return array_values(array_filter($preferredFiles, function (FileInterface $file) {
             return $this->supportChecker->isFormatSupported($file->getFormat());
         }));
     }
     return $preferredFiles;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function extract($source, $target, FormatChainInterface $chainFormat)
 {
     $chainFormats = $chainFormat->getChainFormats();
     foreach ($chainFormats as $format) {
         if (false === $this->supportChecker->isFormatSupported($format)) {
             throw new FileFormatNotSupportedException($source, $format);
         }
     }
     $success = true;
     $lastFile = $source;
     $tempDirectories = [];
     for ($i = 0, $formatsCount = count($chainFormats); $i < $formatsCount && true === $success; $i++) {
         if ($i + 1 === $formatsCount) {
             // last
             $success = $this->extractFormat($lastFile, $target, $chainFormats[$i]);
         } else {
             $tempDirectory = $target . DIRECTORY_SEPARATOR . 'step_' . $i;
             $tempDirectories[] = $tempDirectory;
             $success = $this->extractFormat($lastFile, $tempDirectory, $chainFormats[$i]);
             // look for the uncompressed file
             $iterator = new \FilesystemIterator($tempDirectory, \FilesystemIterator::SKIP_DOTS);
             $extractedFile = null;
             while ($iterator->valid()) {
                 $extractedFile = $iterator->current();
                 $iterator->next();
             }
             if (null === $extractedFile) {
                 throw new FileCorruptedException($lastFile);
             }
             $lastFile = $extractedFile->getRealPath();
         }
     }
     // clean temp directories
     foreach ($tempDirectories as $directory) {
         $this->filesystem->remove($directory);
     }
     return $success;
 }