2011-09-14 12:57:40 +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\Console;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Application as BaseApplication;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2011-12-06 22:07:06 +00:00
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatter;
|
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
2011-09-14 12:57:40 +00:00
|
|
|
use Symfony\Component\Finder\Finder;
|
2011-10-27 23:19:34 +00:00
|
|
|
use Composer\Command;
|
2011-09-20 21:34:06 +00:00
|
|
|
use Composer\Composer;
|
2011-11-30 20:30:51 +00:00
|
|
|
use Composer\Installer;
|
|
|
|
use Composer\Downloader;
|
|
|
|
use Composer\Repository;
|
|
|
|
use Composer\Package;
|
|
|
|
use Composer\Json\JsonFile;
|
2011-09-14 12:57:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console application that handles the commands
|
|
|
|
*
|
|
|
|
* @author Ryan Weaver <ryan@knplabs.com>
|
2011-11-30 20:30:51 +00:00
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
2011-09-14 12:57:40 +00:00
|
|
|
*/
|
|
|
|
class Application extends BaseApplication
|
|
|
|
{
|
2011-11-30 20:30:51 +00:00
|
|
|
protected $composer;
|
2011-09-14 12:57:40 +00:00
|
|
|
|
2011-11-30 20:30:51 +00:00
|
|
|
public function __construct()
|
2011-09-14 12:57:40 +00:00
|
|
|
{
|
|
|
|
parent::__construct('Composer', Composer::VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-06 22:07:06 +00:00
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function run(InputInterface $input = null, OutputInterface $output = null)
|
|
|
|
{
|
|
|
|
if (null === $output) {
|
|
|
|
$styles['highlight'] = new OutputFormatterStyle('red');
|
2011-12-24 14:28:12 +00:00
|
|
|
$styles['warning'] = new OutputFormatterStyle('black', 'yellow');
|
2011-12-06 22:07:06 +00:00
|
|
|
$formatter = new OutputFormatter(null, $styles);
|
|
|
|
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::run($input, $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2011-09-14 12:57:40 +00:00
|
|
|
*/
|
|
|
|
public function doRun(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$this->registerCommands();
|
|
|
|
|
|
|
|
return parent::doRun($input, $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Composer
|
|
|
|
*/
|
|
|
|
public function getComposer()
|
|
|
|
{
|
2011-11-30 20:30:51 +00:00
|
|
|
if (null === $this->composer) {
|
|
|
|
$this->composer = self::bootstrapComposer();
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:57:40 +00:00
|
|
|
return $this->composer;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:30:51 +00:00
|
|
|
/**
|
|
|
|
* Bootstraps a Composer instance
|
|
|
|
*
|
|
|
|
* @return Composer
|
|
|
|
*/
|
|
|
|
public static function bootstrapComposer($composerFile = null)
|
|
|
|
{
|
|
|
|
// load Composer configuration
|
|
|
|
if (null === $composerFile) {
|
2011-11-30 20:50:11 +00:00
|
|
|
$composerFile = getenv('COMPOSER') ?: 'composer.json';
|
2011-11-30 20:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$file = new JsonFile($composerFile);
|
|
|
|
if (!$file->exists()) {
|
|
|
|
if ($composerFile === 'composer.json') {
|
|
|
|
echo 'Composer could not find a composer.json file in '.getcwd().PHP_EOL;
|
|
|
|
} else {
|
|
|
|
echo 'Composer could not find the config file: '.$composerFile.PHP_EOL;
|
|
|
|
}
|
|
|
|
echo 'To initialize a project, please create a composer.json file as described on the http://packagist.org/ "Getting Started" section'.PHP_EOL;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configuration defaults
|
2011-12-03 14:39:06 +00:00
|
|
|
$composerConfig = array(
|
|
|
|
'vendor-dir' => 'vendor',
|
|
|
|
);
|
2011-11-30 20:30:51 +00:00
|
|
|
|
|
|
|
$packageConfig = $file->read();
|
|
|
|
|
|
|
|
if (isset($packageConfig['config']) && is_array($packageConfig['config'])) {
|
|
|
|
$packageConfig['config'] = array_merge($composerConfig, $packageConfig['config']);
|
|
|
|
} else {
|
|
|
|
$packageConfig['config'] = $composerConfig;
|
|
|
|
}
|
|
|
|
|
2011-12-12 20:18:15 +00:00
|
|
|
$vendorDir = getenv('COMPOSER_VENDOR_DIR') ?: $packageConfig['config']['vendor-dir'];
|
2011-12-03 19:47:02 +00:00
|
|
|
if (!isset($packageConfig['config']['bin-dir'])) {
|
|
|
|
$packageConfig['config']['bin-dir'] = $vendorDir.'/bin';
|
|
|
|
}
|
2011-12-12 20:18:15 +00:00
|
|
|
$binDir = getenv('COMPOSER_BIN_DIR') ?: $packageConfig['config']['bin-dir'];
|
2011-11-30 20:30:51 +00:00
|
|
|
|
|
|
|
// initialize repository manager
|
|
|
|
$rm = new Repository\RepositoryManager();
|
|
|
|
$rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile($vendorDir.'/.composer/installed.json')));
|
|
|
|
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
|
|
|
|
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
|
|
|
|
$rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
|
|
|
|
$rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
|
|
|
|
|
|
|
|
// initialize download manager
|
|
|
|
$dm = new Downloader\DownloadManager();
|
|
|
|
$dm->setDownloader('git', new Downloader\GitDownloader());
|
|
|
|
$dm->setDownloader('svn', new Downloader\SvnDownloader());
|
|
|
|
$dm->setDownloader('hg', new Downloader\HgDownloader());
|
|
|
|
$dm->setDownloader('pear', new Downloader\PearDownloader());
|
|
|
|
$dm->setDownloader('zip', new Downloader\ZipDownloader());
|
|
|
|
|
|
|
|
// initialize installation manager
|
|
|
|
$im = new Installer\InstallationManager($vendorDir);
|
2011-12-03 14:39:06 +00:00
|
|
|
$im->addInstaller(new Installer\LibraryInstaller($vendorDir, $binDir, $dm, $rm->getLocalRepository(), null));
|
|
|
|
$im->addInstaller(new Installer\InstallerInstaller($vendorDir, $binDir, $dm, $rm->getLocalRepository(), $im));
|
2011-11-30 20:30:51 +00:00
|
|
|
|
|
|
|
// load package
|
2011-12-12 20:46:21 +00:00
|
|
|
$loader = new Package\Loader\RootPackageLoader($rm);
|
2011-11-30 20:30:51 +00:00
|
|
|
$package = $loader->load($packageConfig);
|
|
|
|
|
|
|
|
// load default repository unless it's explicitly disabled
|
|
|
|
if (!isset($packageConfig['repositories']['packagist']) || $packageConfig['repositories']['packagist'] !== false) {
|
2011-12-03 11:46:28 +00:00
|
|
|
$rm->addRepository(new Repository\ComposerRepository(array('url' => 'http://packagist.org')));
|
2011-11-30 20:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// init locker
|
2011-11-30 20:50:11 +00:00
|
|
|
$lockFile = substr($composerFile, -5) === '.json' ? substr($composerFile, 0, -4).'lock' : $composerFile . '.lock';
|
2011-12-24 14:28:12 +00:00
|
|
|
$locker = new Package\Locker(new JsonFile($lockFile), $rm, md5_file($composerFile));
|
2011-11-30 20:30:51 +00:00
|
|
|
|
|
|
|
// initialize composer
|
|
|
|
$composer = new Composer();
|
|
|
|
$composer->setPackage($package);
|
|
|
|
$composer->setLocker($locker);
|
|
|
|
$composer->setRepositoryManager($rm);
|
|
|
|
$composer->setDownloadManager($dm);
|
|
|
|
$composer->setInstallationManager($im);
|
|
|
|
|
|
|
|
return $composer;
|
|
|
|
}
|
|
|
|
|
2011-09-20 21:34:06 +00:00
|
|
|
/**
|
2011-09-25 21:19:12 +00:00
|
|
|
* Initializes all the composer commands
|
2011-09-14 12:57:40 +00:00
|
|
|
*/
|
|
|
|
protected function registerCommands()
|
|
|
|
{
|
2011-11-08 10:51:01 +00:00
|
|
|
$this->add(new Command\AboutCommand());
|
2012-01-05 03:11:37 +00:00
|
|
|
$this->add(new Command\DependsCommand());
|
2011-10-27 23:19:34 +00:00
|
|
|
$this->add(new Command\InstallCommand());
|
2011-10-30 22:15:55 +00:00
|
|
|
$this->add(new Command\UpdateCommand());
|
2011-10-27 23:19:34 +00:00
|
|
|
$this->add(new Command\DebugPackagesCommand());
|
2011-12-06 17:04:55 +00:00
|
|
|
$this->add(new Command\SearchCommand());
|
2011-12-07 20:29:18 +00:00
|
|
|
$this->add(new Command\ValidateCommand());
|
2011-12-07 16:09:01 +00:00
|
|
|
$this->add(new Command\ShowCommand());
|
2011-11-16 12:49:00 +00:00
|
|
|
|
|
|
|
if ('phar:' === substr(__FILE__, 0, 5)) {
|
|
|
|
$this->add(new Command\SelfUpdateCommand());
|
|
|
|
}
|
2011-09-14 12:57:40 +00:00
|
|
|
}
|
2011-09-20 21:34:06 +00:00
|
|
|
}
|