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.

132 lines
3.2 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\Command;
use Composer\Composer;
use Composer\Console\Application;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
/**
* Base class for Composer commands
*
* @author Ryan Weaver <ryan@knplabs.com>
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
abstract class BaseCommand extends Command
{
/**
12 years ago
* @var Composer
*/
private $composer;
/**
12 years ago
* @var IOInterface
*/
private $io;
/**
11 years ago
* @param bool $required
* @param bool|null $disablePlugins
* @throws \RuntimeException
12 years ago
* @return Composer
*/
public function getComposer($required = true, $disablePlugins = null)
{
if (null === $this->composer) {
$application = $this->getApplication();
if ($application instanceof Application) {
/* @var $application Application */
$this->composer = $application->getComposer($required, $disablePlugins);
} elseif ($required) {
throw new \RuntimeException(
'Could not create a Composer\Composer instance, you must inject '.
'one if this command is not used with a Composer\Console\Application instance'
);
}
}
return $this->composer;
}
/**
12 years ago
* @param Composer $composer
*/
public function setComposer(Composer $composer)
{
$this->composer = $composer;
}
/**
* Removes the cached composer instance
*/
public function resetComposer()
{
$this->composer = null;
$this->getApplication()->resetComposer();
}
/**
* Whether or not this command is meant to call another command.
*
* This is mainly needed to avoid duplicated warnings messages.
*
* @return bool
*/
public function isProxyCommand()
{
return false;
}
/**
12 years ago
* @return IOInterface
*/
public function getIO()
{
if (null === $this->io) {
$application = $this->getApplication();
if ($application instanceof Application) {
/* @var $application Application */
$this->io = $application->getIO();
} else {
$this->io = new NullIO();
}
}
return $this->io;
}
/**
12 years ago
* @param IOInterface $io
*/
public function setIO(IOInterface $io)
{
$this->io = $io;
}
/**
* {@inheritDoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
if (true === $input->hasParameterOption(array('--no-ansi')) && $input->hasOption('no-progress')) {
$input->setOption('no-progress', true);
}
parent::initialize($input, $output);
}
}