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-10-27 23:19:34 +00:00
use Composer\Command ;
2012-01-08 22:40:30 +00:00
use Composer\Command\Helper\DialogHelper ;
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 ;
2012-01-27 08:29:07 +00:00
use Composer\Util\ErrorHandler ;
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
{
2012-05-08 21:26:01 +00:00
/**
* @ var Composer
*/
2011-11-30 20:30:51 +00:00
protected $composer ;
2012-05-08 21:26:01 +00:00
/**
2012-06-23 09:47:53 +00:00
* @ var IOInterface
2012-05-08 21:26:01 +00:00
*/
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
{
2012-03-18 20:16:36 +00:00
ErrorHandler :: register ();
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 )
{
2012-01-16 13:14:15 +00:00
$this -> io = new ConsoleIO ( $input , $output , $this -> getHelperSet ());
2012-01-10 17:50:16 +00:00
2012-04-29 14:07:47 +00:00
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>' );
}
2012-06-24 10:18:07 +00:00
if ( defined ( 'COMPOSER_DEV_WARNING_TIME' ) && $this -> getCommandName ( $input ) !== 'self-update' ) {
if ( time () > COMPOSER_DEV_WARNING_TIME ) {
$output -> writeln ( sprintf ( '<warning>This dev build of composer is outdated, please run "%s self-update" to get the latest version.</warning>' , $_SERVER [ 'PHP_SELF' ]));
}
}
2011-09-14 12:57:40 +00:00
return parent :: doRun ( $input , $output );
}
/**
2012-06-23 09:58:18 +00:00
* @ param bool $required
* @ return \Composer\Composer
2011-09-14 12:57:40 +00:00
*/
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 );
}
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
*/
2012-05-27 22:10:02 +00:00
protected function getDefaultCommands ()
2011-09-14 12:57:40 +00:00
{
2012-05-27 22:10:02 +00:00
$commands = parent :: getDefaultCommands ();
$commands [] = new Command\AboutCommand ();
$commands [] = new Command\DependsCommand ();
$commands [] = new Command\InitCommand ();
$commands [] = new Command\InstallCommand ();
$commands [] = new Command\CreateProjectCommand ();
$commands [] = new Command\UpdateCommand ();
$commands [] = new Command\SearchCommand ();
$commands [] = new Command\ValidateCommand ();
$commands [] = new Command\ShowCommand ();
$commands [] = new Command\RequireCommand ();
2012-06-25 12:20:50 +00:00
$commands [] = new Command\DumpAutoloadCommand ();
2012-06-25 23:18:10 +00:00
$commands [] = new Command\StatusCommand ();
2011-11-16 12:49:00 +00:00
if ( 'phar:' === substr ( __FILE__ , 0 , 5 )) {
2012-05-27 22:10:02 +00:00
$commands [] = new Command\SelfUpdateCommand ();
2011-11-16 12:49:00 +00:00
}
2012-05-27 22:10:02 +00:00
return $commands ;
2011-09-14 12:57:40 +00:00
}
2012-01-08 22:40:30 +00:00
/**
* { @ inheritDoc }
*/
protected function getDefaultHelperSet ()
{
$helperSet = parent :: getDefaultHelperSet ();
$helperSet -> set ( new DialogHelper ());
return $helperSet ;
}
2011-09-20 21:34:06 +00:00
}