You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.8 KiB
PHTML

<?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;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Composer\Command;
use Composer\Command\Helper\DialogHelper;
use Composer\Composer;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\IO\ConsoleIO;
use Composer\Util\ErrorHandler;
/**
* The console application that handles the commands
*
* @author Ryan Weaver <ryan@knplabs.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class Application extends BaseApplication
{
protected $composer;
protected $io;
public function __construct()
{
12 years ago
ErrorHandler::register();
parent::__construct('Composer', Composer::VERSION);
}
/**
* {@inheritDoc}
*/
public function run(InputInterface $input = null, OutputInterface $output = null)
{
if (null === $output) {
$styles['highlight'] = new OutputFormatterStyle('red');
$styles['warning'] = new OutputFormatterStyle('black', 'yellow');
$formatter = new OutputFormatter(null, $styles);
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter);
}
return parent::run($input, $output);
}
/**
* {@inheritDoc}
*/
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->registerCommands();
$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
if (version_compare(PHP_VERSION, '5.3.2', '<')) {
$output->writeln('<warning>Composer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP '.PHP_VERSION.', upgrading is strongly recommended.</warning>');
}
return parent::doRun($input, $output);
}
/**
* @return Composer
*/
public function getComposer($required = true)
{
if (null === $this->composer) {
try {
$this->composer = Factory::create($this->io);
} catch (\InvalidArgumentException $e) {
if ($required) {
$this->io->write($e->getMessage());
exit(1);
}
return;
}
}
return $this->composer;
}
/**
* @return IOInterface
*/
public function getIO()
{
return $this->io;
}
/**
* Initializes all the composer commands
*/
protected function registerCommands()
{
$this->add(new Command\AboutCommand());
$this->add(new Command\DependsCommand());
$this->add(new Command\InitCommand());
$this->add(new Command\InstallCommand());
$this->add(new Command\CreateProjectCommand());
$this->add(new Command\UpdateCommand());
$this->add(new Command\SearchCommand());
$this->add(new Command\ValidateCommand());
$this->add(new Command\ShowCommand());
if ('phar:' === substr(__FILE__, 0, 5)) {
$this->add(new Command\SelfUpdateCommand());
}
}
/**
* {@inheritDoc}
*/
protected function getDefaultHelperSet()
{
$helperSet = parent::getDefaultHelperSet();
$helperSet->set(new DialogHelper());
return $helperSet;
}
}