PearInstaller.php 2.8 KB

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