PearInstaller.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\Installer;
  12. use Composer\IO\IOInterface;
  13. use Composer\Composer;
  14. use Composer\Downloader\PearPackageExtractor;
  15. use Composer\Repository\InstalledRepositoryInterface;
  16. use Composer\Package\PackageInterface;
  17. use Composer\Util\Platform;
  18. use Composer\Util\Filesystem;
  19. /**
  20. * Package installation manager.
  21. *
  22. * @author Jordi Boggiano <j.boggiano@seld.be>
  23. * @author Konstantin Kudryashov <ever.zet@gmail.com>
  24. */
  25. class PearInstaller extends LibraryInstaller
  26. {
  27. /**
  28. * Initializes library installer.
  29. *
  30. * @param IOInterface $io io instance
  31. * @param Composer $composer
  32. * @param string $type package type that this installer handles
  33. */
  34. public function __construct(IOInterface $io, Composer $composer, $type = 'pear-library')
  35. {
  36. $filesystem = new Filesystem();
  37. $binaryInstaller = new PearBinaryInstaller($io, rtrim($composer->getConfig()->get('bin-dir'), '/'), rtrim($composer->getConfig()->get('vendor-dir'), '/'), $composer->getConfig()->get('bin-compat'), $filesystem, $this);
  38. parent::__construct($io, $composer, $type, $filesystem, $binaryInstaller);
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  44. {
  45. $this->uninstall($repo, $initial);
  46. $this->install($repo, $target);
  47. }
  48. protected function installCode(PackageInterface $package)
  49. {
  50. parent::installCode($package);
  51. $isWindows = Platform::isWindows();
  52. $php_bin = $this->binDir . ($isWindows ? '/composer-php.bat' : '/composer-php');
  53. if (!$isWindows) {
  54. $php_bin = '/usr/bin/env ' . $php_bin;
  55. }
  56. $installPath = $this->getInstallPath($package);
  57. $vars = array(
  58. 'os' => $isWindows ? 'windows' : 'linux',
  59. 'php_bin' => $php_bin,
  60. 'pear_php' => $installPath,
  61. 'php_dir' => $installPath,
  62. 'bin_dir' => $installPath . '/bin',
  63. 'data_dir' => $installPath . '/data',
  64. 'version' => $package->getPrettyVersion(),
  65. );
  66. $packageArchive = $this->getInstallPath($package).'/'.pathinfo($package->getDistUrl(), PATHINFO_BASENAME);
  67. $pearExtractor = new PearPackageExtractor($packageArchive);
  68. $pearExtractor->extractTo($this->getInstallPath($package), array('php' => '/', 'script' => '/bin', 'data' => '/data'), $vars);
  69. $this->io->writeError(' Cleaning up', true, IOInterface::VERBOSE);
  70. $this->filesystem->unlink($packageArchive);
  71. }
  72. }