GzipDownloader.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Downloader;
  12. use Composer\Config;
  13. use Composer\Cache;
  14. use Composer\EventDispatcher\EventDispatcher;
  15. use Composer\Package\PackageInterface;
  16. use Composer\Util\ProcessExecutor;
  17. use Composer\IO\IOInterface;
  18. /**
  19. * GZip archive downloader.
  20. *
  21. * @author Pavel Puchkin <i@neoascetic.me>
  22. */
  23. class GzipDownloader extends ArchiveDownloader
  24. {
  25. protected $process;
  26. public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
  27. {
  28. $this->process = $process ?: new ProcessExecutor($io);
  29. parent::__construct($io, $config, $eventDispatcher, $cache);
  30. }
  31. protected function extract($file, $path)
  32. {
  33. $targetFile = $path . '/' . basename(substr($file, 0, -3));
  34. $command = 'gzip -cd ' . escapeshellarg($file) . ' > ' . escapeshellarg($targetFile);
  35. if (0 === $this->process->execute($command, $ignoredOutput)) {
  36. return;
  37. }
  38. $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
  39. throw new \RuntimeException($processError);
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. protected function getFileName(PackageInterface $package, $path)
  45. {
  46. return $path.'/'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME);
  47. }
  48. }