/** * @param string $archiveFile * @param string $targetDir * @param OutputInterface $output */ public function extractArchive($archiveFile, $targetDir, OutputInterface $output) { if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) { $output->write(sprintf('Extracting <comment>%s</comment> to <comment>%s</comment>...', $archiveFile, $targetDir)); } $processHelper = $this->getHelperSet()->get('process'); /* @var $processHelper ProcessHelper */ $tempDir = $this->getTempDir($archiveFile); $extractProcess = Util::getExtractProcess($archiveFile); if (!$extractProcess) { throw new \RuntimeException(sprintf('Archive type of %s cannot be handled', $archiveFile)); } $extractProcess->setWorkingDirectory($tempDir); $processHelper->mustRun($output, $extractProcess); $commonPrefix = PathUtil::commonPrefix(Finder::create()->ignoreDotFiles(false)->ignoreVCS(false)->directories()->in($tempDir)); FsUtil::rename($commonPrefix, $targetDir); foreach (Finder::create()->ignoreDotFiles(false)->ignoreVCS(false)->directories()->in($tempDir) as $files) { FsUtil::rmdir($files); } if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) { $output->writeln('<info>OK</info>'); } }
public static function assert($filename, $configOption, $configValue) { if (!PathUtil::isSubDirectory($filename, $configValue)) { throw new self($filename, $configOption, $configValue); } }