PathDownloader.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Package\PackageInterface;
  13. use Symfony\Component\Filesystem\Exception\IOException;
  14. use Symfony\Component\Filesystem\Filesystem;
  15. /**
  16. * Download a package from a local path.
  17. *
  18. * @author Samuel Roze <samuel.roze@gmail.com>
  19. * @author Johann Reinke <johann.reinke@gmail.com>
  20. */
  21. class PathDownloader extends FileDownloader
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function download(PackageInterface $package, $path)
  27. {
  28. $fileSystem = new Filesystem();
  29. $this->filesystem->removeDirectory($path);
  30. $this->io->writeError(sprintf(
  31. ' - Installing <info>%s</info> (<comment>%s</comment>)',
  32. $package->getName(),
  33. $package->getFullPrettyVersion()
  34. ));
  35. $url = $package->getDistUrl();
  36. $realUrl = realpath($url);
  37. if (false === $realUrl || !file_exists($realUrl) || !is_dir($realUrl)) {
  38. throw new \RuntimeException(sprintf(
  39. 'Path "%s" is not found',
  40. $url
  41. ));
  42. }
  43. try {
  44. $shortestPath = $this->filesystem->findShortestPath($path, $realUrl);
  45. $fileSystem->symlink($shortestPath, $path);
  46. $this->io->writeError(sprintf(' Symlinked from %s', $url));
  47. } catch (IOException $e) {
  48. $fileSystem->mirror($realUrl, $path);
  49. $this->io->writeError(sprintf(' Mirrored from %s', $url));
  50. }
  51. $this->io->writeError('');
  52. }
  53. }