2012-06-27 05:27:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Installer;
|
|
|
|
|
|
|
|
use Composer\IO\IOInterface;
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Downloader\PearPackageExtractor;
|
|
|
|
use Composer\Repository\InstalledRepositoryInterface;
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Package installation manager.
|
|
|
|
*
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
|
|
|
*/
|
|
|
|
class PearInstaller extends LibraryInstaller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initializes library installer.
|
|
|
|
*
|
2012-07-08 04:20:35 +00:00
|
|
|
* @param IOInterface $io io instance
|
|
|
|
* @param Composer $composer
|
|
|
|
* @param string $type package type that this installer handles
|
2012-06-27 05:27:01 +00:00
|
|
|
*/
|
|
|
|
public function __construct(IOInterface $io, Composer $composer, $type = 'pear-library')
|
|
|
|
{
|
|
|
|
parent::__construct($io, $composer, $type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
|
|
|
|
{
|
|
|
|
$this->uninstall($repo, $initial);
|
|
|
|
$this->install($repo, $target);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function installCode(PackageInterface $package)
|
|
|
|
{
|
|
|
|
parent::installCode($package);
|
2012-07-08 04:20:35 +00:00
|
|
|
parent::initializeBinDir();
|
2012-06-27 05:27:01 +00:00
|
|
|
|
2012-08-15 10:29:43 +00:00
|
|
|
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
|
2012-07-08 04:20:35 +00:00
|
|
|
$php_bin = $this->binDir . ($isWindows ? '/composer-php.bat' : '/composer-php');
|
2012-06-27 05:27:01 +00:00
|
|
|
|
2012-08-30 12:56:20 +00:00
|
|
|
if (!$isWindows) {
|
|
|
|
$php_bin = '/usr/bin/env ' . $php_bin;
|
|
|
|
}
|
|
|
|
|
2012-07-05 12:44:25 +00:00
|
|
|
$installPath = $this->getInstallPath($package);
|
2012-06-27 05:27:01 +00:00
|
|
|
$vars = array(
|
|
|
|
'os' => $isWindows ? 'windows' : 'linux',
|
2012-07-05 12:44:25 +00:00
|
|
|
'php_bin' => $php_bin,
|
|
|
|
'pear_php' => $installPath,
|
|
|
|
'php_dir' => $installPath,
|
|
|
|
'bin_dir' => $installPath . '/bin',
|
|
|
|
'data_dir' => $installPath . '/data',
|
2012-06-27 05:27:01 +00:00
|
|
|
'version' => $package->getPrettyVersion(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$packageArchive = $this->getInstallPath($package).'/'.pathinfo($package->getDistUrl(), PATHINFO_BASENAME);
|
|
|
|
$pearExtractor = new PearPackageExtractor($packageArchive);
|
2012-07-05 12:44:25 +00:00
|
|
|
$pearExtractor->extractTo($this->getInstallPath($package), array('php' => '/', 'script' => '/bin', 'data' => '/data'), $vars);
|
2012-06-27 05:27:01 +00:00
|
|
|
|
|
|
|
if ($this->io->isVerbose()) {
|
|
|
|
$this->io->write(' Cleaning up');
|
|
|
|
}
|
|
|
|
unlink($packageArchive);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getBinaries(PackageInterface $package)
|
|
|
|
{
|
|
|
|
$binariesPath = $this->getInstallPath($package) . '/bin/';
|
|
|
|
$binaries = array();
|
|
|
|
if (file_exists($binariesPath)) {
|
2012-07-08 04:20:35 +00:00
|
|
|
foreach (new \FilesystemIterator($binariesPath, \FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO) as $fileName => $value) {
|
|
|
|
if (!$value->isDir()) {
|
|
|
|
$binaries[] = 'bin/'.$fileName;
|
|
|
|
}
|
2012-06-27 05:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $binaries;
|
|
|
|
}
|
2012-07-03 13:38:29 +00:00
|
|
|
|
|
|
|
protected function initializeBinDir()
|
|
|
|
{
|
|
|
|
parent::initializeBinDir();
|
|
|
|
file_put_contents($this->binDir.'/composer-php', $this->generateUnixyPhpProxyCode());
|
|
|
|
chmod($this->binDir.'/composer-php', 0777);
|
|
|
|
file_put_contents($this->binDir.'/composer-php.bat', $this->generateWindowsPhpProxyCode());
|
|
|
|
chmod($this->binDir.'/composer-php.bat', 0777);
|
|
|
|
}
|
|
|
|
|
2012-08-15 10:29:43 +00:00
|
|
|
protected function generateWindowsProxyCode($bin, $link)
|
|
|
|
{
|
|
|
|
$binPath = $this->filesystem->findShortestPath($link, $bin);
|
|
|
|
if ('.bat' === substr($bin, -4)) {
|
|
|
|
$caller = 'call';
|
|
|
|
} else {
|
|
|
|
$handle = fopen($bin, 'r');
|
|
|
|
$line = fgets($handle);
|
|
|
|
fclose($handle);
|
|
|
|
if (preg_match('{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m', $line, $match)) {
|
|
|
|
$caller = trim($match[1]);
|
|
|
|
} else {
|
|
|
|
$caller = 'php';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($caller === 'php') {
|
|
|
|
return "@echo off\r\n".
|
|
|
|
"pushd .\r\n".
|
|
|
|
"cd %~dp0\r\n".
|
|
|
|
"set PHP_PROXY=%CD%\\composer-php.bat\r\n".
|
|
|
|
"cd ".escapeshellarg(dirname($binPath))."\r\n".
|
|
|
|
"set BIN_TARGET=%CD%\\".basename($binPath)."\r\n".
|
|
|
|
"popd\r\n".
|
|
|
|
"%PHP_PROXY% \"%BIN_TARGET%\" %*\r\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "@echo off\r\n".
|
|
|
|
"pushd .\r\n".
|
|
|
|
"cd %~dp0\r\n".
|
|
|
|
"cd ".escapeshellarg(dirname($binPath))."\r\n".
|
|
|
|
"set BIN_TARGET=%CD%\\".basename($binPath)."\r\n".
|
|
|
|
"popd\r\n".
|
|
|
|
$caller." \"%BIN_TARGET%\" %*\r\n";
|
|
|
|
}
|
|
|
|
|
2012-07-03 13:38:29 +00:00
|
|
|
private function generateWindowsPhpProxyCode()
|
|
|
|
{
|
2012-08-15 10:29:43 +00:00
|
|
|
$binToVendor = $this->filesystem->findShortestPath($this->binDir, $this->vendorDir, true);
|
|
|
|
|
2012-07-03 13:38:29 +00:00
|
|
|
return
|
|
|
|
"@echo off\r\n" .
|
|
|
|
"setlocal enabledelayedexpansion\r\n" .
|
|
|
|
"set BIN_DIR=%~dp0\r\n" .
|
2012-08-15 10:29:43 +00:00
|
|
|
"set VENDOR_DIR=%BIN_DIR%\\".$binToVendor."\r\n" .
|
|
|
|
"set DIRS=.\r\n" .
|
|
|
|
"FOR /D %%V IN (%VENDOR_DIR%\\*) DO (\r\n" .
|
2012-07-03 13:38:29 +00:00
|
|
|
" FOR /D %%P IN (%%V\\*) DO (\r\n" .
|
|
|
|
" set DIRS=!DIRS!;%%~fP\r\n" .
|
|
|
|
" )\r\n" .
|
|
|
|
")\r\n" .
|
|
|
|
"php.exe -d include_path=!DIRS! %*\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
private function generateUnixyPhpProxyCode()
|
|
|
|
{
|
2012-08-15 10:29:43 +00:00
|
|
|
$binToVendor = $this->filesystem->findShortestPath($this->binDir, $this->vendorDir, true);
|
|
|
|
|
2012-07-03 13:38:29 +00:00
|
|
|
return
|
|
|
|
"#!/usr/bin/env sh\n".
|
|
|
|
"SRC_DIR=`pwd`\n".
|
2012-08-30 12:56:20 +00:00
|
|
|
"BIN_DIR=`dirname $0`\n".
|
2012-08-15 10:29:43 +00:00
|
|
|
"VENDOR_DIR=\$BIN_DIR/".escapeshellarg($binToVendor)."\n".
|
2012-07-03 13:38:29 +00:00
|
|
|
"DIRS=\"\"\n".
|
|
|
|
"for vendor in \$VENDOR_DIR/*; do\n".
|
|
|
|
" if [ -d \"\$vendor\" ]; then\n".
|
|
|
|
" for package in \$vendor/*; do\n".
|
|
|
|
" if [ -d \"\$package\" ]; then\n".
|
|
|
|
" DIRS=\"\${DIRS}:\${package}\"\n".
|
|
|
|
" fi\n".
|
|
|
|
" done\n".
|
|
|
|
" fi\n".
|
|
|
|
"done\n".
|
2012-08-15 10:29:43 +00:00
|
|
|
"php -d include_path=\".\$DIRS\" $@\n";
|
2012-07-03 13:38:29 +00:00
|
|
|
}
|
2012-06-27 05:27:01 +00:00
|
|
|
}
|