123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?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 Symfony\Component\Finder\Finder;
- use Composer\Command;
- use Composer\Command\Helper\DialogHelper;
- use Composer\Composer;
- use Composer\Factory;
- use Composer\IO\IOInterface;
- use Composer\IO\ConsoleIO;
- /**
- * 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()
- {
- 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());
- 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;
- }
- }
|