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;
|
2012-01-11 12:55:05 +00:00
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
2011-12-06 22:07:06 +00:00
|
|
|
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;
|
2012-01-17 09:00:53 +00:00
|
|
|
use Composer\Factory;
|
2012-01-17 22:07:33 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2012-01-16 13:14:15 +00:00
|
|
|
use Composer\IO\ConsoleIO;
|
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>
|
2012-01-10 17:50:16 +00:00
|
|
|
* @author François Pluchino <francois.pluchino@opendisplay.com>
|
2011-09-14 12:57:40 +00:00
|
|
|
*/
|
|
|
|
class Application extends BaseApplication
|
|
|
|
{
|
2011-11-30 20:30:51 +00:00
|
|
|
protected $composer;
|
2012-01-16 13:14:15 +00:00
|
|
|
protected $io;
|
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();
|
2012-01-16 13:14:15 +00:00
|
|
|
$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
|
2012-01-10 17:50:16 +00:00
|
|
|
|
2011-09-14 12:57:40 +00:00
|
|
|
return parent::doRun($input, $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Composer
|
|
|
|
*/
|
2012-02-08 09:24:36 +00:00
|
|
|
public function getComposer($required = true)
|
2011-09-14 12:57:40 +00:00
|
|
|
{
|
2011-11-30 20:30:51 +00:00
|
|
|
if (null === $this->composer) {
|
2012-01-17 09:00:53 +00:00
|
|
|
try {
|
2012-01-17 16:56:06 +00:00
|
|
|
$this->composer = Factory::create($this->io);
|
2012-01-17 09:00:53 +00:00
|
|
|
} catch (\InvalidArgumentException $e) {
|
2012-02-08 09:24:36 +00:00
|
|
|
if ($required) {
|
|
|
|
$this->io->write($e->getMessage());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2011-11-30 20:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:57:40 +00:00
|
|
|
return $this->composer;
|
|
|
|
}
|
|
|
|
|
2012-01-16 19:44:06 +00:00
|
|
|
/**
|
|
|
|
* @return IOInterface
|
|
|
|
*/
|
|
|
|
public function getIO()
|
|
|
|
{
|
|
|
|
return $this->io;
|
|
|
|
}
|
|
|
|
|
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());
|
2012-01-04 00:57:31 +00:00
|
|
|
$this->add(new Command\InitCommand());
|
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-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
|
|
|
}
|