protected function execute(InputInterface $input, OutputInterface $output, Command $command) { $command->setIO(new ConsoleIO($input, $output, $this->getHelperSet())); $application = $this->application; $application->add($command); $application->setAutoExit(false); return $application->run($input, $output); }
public function run(InputInterface $input, OutputInterface $output) { // extract real command name $tokens = preg_split('{\\s+}', $input->__toString()); $args = array(); foreach ($tokens as $token) { if ($token && $token[0] !== '-') { $args[] = $token; if (count($args) >= 2) { break; } } } // show help for this command if no command was found if (count($args) < 2) { return parent::run($input, $output); } // change to global dir $config = Factory::createConfig(); chdir($config->get('home')); $this->getIO()->writeError('<info>Changed current directory to ' . $config->get('home') . '</info>'); // create new input without "global" command prefix $input = new StringInput(preg_replace('{\\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\\b}', '', $input->__toString(), 1)); $this->getApplication()->resetComposer(); return $this->getApplication()->run($input, $output); }
/** * {@inheritDoc} */ protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); if ($input->getOption('global') && null !== $input->getOption('file')) { throw new \RuntimeException('--file and --global can not be combined'); } $io = $this->getIO(); $this->config = Factory::createConfig($io); // Get the local composer.json, global config.json, or if the user // passed in a file to use $configFile = $input->getOption('global') ? $this->config->get('home') . '/config.json' : ($input->getOption('file') ?: trim(getenv('COMPOSER')) ?: 'composer.json'); // Create global composer.json if this was invoked using `composer global config` if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) { file_put_contents($configFile, "{\n}\n"); } $this->configFile = new JsonFile($configFile, null, $io); $this->configSource = new JsonConfigSource($this->configFile); $authConfigFile = $input->getOption('global') ? $this->config->get('home') . '/auth.json' : dirname(realpath($configFile)) . '/auth.json'; $this->authConfigFile = new JsonFile($authConfigFile, null, $io); $this->authConfigSource = new JsonConfigSource($this->authConfigFile, true); // Initialize the global file if it's not there, ignoring any warnings or notices if ($input->getOption('global') && !$this->configFile->exists()) { touch($this->configFile->getPath()); $this->configFile->write(array('config' => new \ArrayObject())); Silencer::call('chmod', $this->configFile->getPath(), 0600); } if ($input->getOption('global') && !$this->authConfigFile->exists()) { touch($this->authConfigFile->getPath()); $this->authConfigFile->write(array('http-basic' => new \ArrayObject(), 'github-oauth' => new \ArrayObject(), 'gitlab-oauth' => new \ArrayObject())); Silencer::call('chmod', $this->authConfigFile->getPath(), 0600); } if (!$this->configFile->exists()) { throw new \RuntimeException(sprintf('File "%s" cannot be found in the current directory', $configFile)); } }
public function __construct() { require_once self::getRootDir() . 'vendor/autoload.php'; parent::__construct(); }
public function __construct(\PHPUnit_Framework_Assert $assert) { $this->assert = $assert; parent::__construct('mytest'); $this->setDefinition(array(new InputOption('myoption', null, InputOption::VALUE_NONE))); }
/** * Execute the command and throw exceptions on errors. * * @param BaseCommand $command The command to execute. * * @param InputInterface $input The input to use. * * @param OutputInterface $output The output to use. * * @return void * * @throws \RuntimeException On exceptions or when the command has an non zero exit code. */ protected function executeCommand(BaseCommand $command, InputInterface $input, OutputInterface $output) { try { if (0 !== ($statusCode = $command->run($input, $output))) { throw new \RuntimeException('Error: command exit code was ' . $statusCode); } } catch (\Exception $exception) { throw new \RuntimeException($exception->getMessage(), $exception->getCode(), $exception); } }
public function __construct($script) { $this->script = $script; parent::__construct(); }