protected function getMaxUncompressionSpeedFormatChain(FormatChainInterface $formatChain, array $methods) { $maxSpeed = MethodInterface::SPEED_LEVEL_LOWEST; foreach ($formatChain->getChainFormats() as $format) { $maxSpeed = max($maxSpeed, $this->getMaxUncompressionSpeedFormat($format, $methods)); } return $maxSpeed; }
/** * {@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; }
/** * {@inheritdoc} */ public function getUnsupportedFormatsFromChain(FormatChainInterface $formatChain) { $formats = []; foreach ($formatChain->getChainFormats() as $format) { if (false === $this->isFormatSupported($format)) { $formats[] = $format; } } return $formats; }