12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?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\Command\Command as BaseCommand;
- /**
- * Base class for Composer commands
- *
- * @author Ryan Weaver <ryan@knplabs.com>
- * @author Konstantin Kudryashov <ever.zet@gmail.com>
- */
- abstract class Command extends BaseCommand
- {
- /**
- * @var \Composer\Composer
- */
- private $composer;
- /**
- * @var \Composer\IO\IOInterface
- */
- private $io;
- /**
- * @param bool $required
- * @return \Composer\Composer
- */
- public function getComposer($required = true)
- {
- if (null === $this->composer) {
- $application = $this->getApplication();
- if ($application instanceof Application) {
- /* @var $application Application */
- $this->composer = $application->getComposer($required);
- } 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;
- }
- /**
- * @param \Composer\Composer $composer
- */
- public function setComposer(Composer $composer)
- {
- $this->composer = $composer;
- }
- /**
- * @return \Composer\IO\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;
- }
- /**
- * @param \Composer\IO\IOInterface $io
- */
- public function setIO(IOInterface $io)
- {
- $this->io = $io;
- }
- }
|