Sets the application instance for this command.
public setApplication ( |
||
$application | An Application instance |
/** * @param string $entityManagerName * @return string */ protected function wrapCommand($entityManagerName) { if (!$this->isVersionCompatible()) { throw new \RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion())); } DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $entityManagerName); $this->command->setApplication($this->getApplication()); return $this->command; }
public function testConsoleEvent() { $dispatcher = new EventDispatcher(); $listener = new DebugHandlersListener(null); $app = $this->getMock('Symfony\\Component\\Console\\Application'); $app->expects($this->once())->method('getHelperSet')->will($this->returnValue(new HelperSet())); $command = new Command(__FUNCTION__); $command->setApplication($app); $event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput()); $dispatcher->addSubscriber($listener); $xListeners = array(KernelEvents::REQUEST => array(array($listener, 'configure')), ConsoleEvents::COMMAND => array(array($listener, 'configure'))); $this->assertSame($xListeners, $dispatcher->getListeners()); $exception = null; $eHandler = new ErrorHandler(); set_error_handler(array($eHandler, 'handleError')); set_exception_handler(array($eHandler, 'handleException')); try { $dispatcher->dispatch(ConsoleEvents::COMMAND, $event); } catch (\Exception $exception) { } restore_exception_handler(); restore_error_handler(); if (null !== $exception) { throw $exception; } $xHandler = $eHandler->setExceptionHandler('var_dump'); $this->assertInstanceOf('Closure', $xHandler); $app->expects($this->once())->method('renderException'); $xHandler(new \Exception()); }
/** * Sets the application instance for this command. * * @param Application $application * An Application instance * * @api */ public function setApplication(Application $application = null) { if ($application !== null && !$application instanceof Shell) { throw new \InvalidArgumentException('PsySH Commands require an instance of Psy\\Shell.'); } return parent::setApplication($application); }
public static function postInstall(Event $event) { // Check if npm is installed exec('hash npm 2>/dev/null || { exit 1; }', $result, $returnVar); $npmInstalled = $returnVar == 0 ? true : false; if ($npmInstalled === true) { // Instantiate the Command $command = new Command('post-create'); $command->setApplication(new Application()); // Load the dialog helper $dialog = $command->getHelperSet()->get('dialog'); // Write output to the console $output = new ConsoleOutput(); if ($dialog->askConfirmation($output, "\n<info>Install Gulp and it's dependencies?</info> [<comment>Y,n</comment>]? ", false)) { // Check if npm is installed exec('hash gulp 2>/dev/null || { exit 1; }', $out, $returnVar); $gulpInstalled = $returnVar == 0 ? true : false; if ($gulpInstalled === false) { $output->writeln("\n<info>Installing Gulp</info>\n"); $output->writeln("\$ sudo npm install -g gulp\n"); exec('sudo npm install -g gulp'); } $output->writeln("\n<info>Installing dependencies</info>\n"); $output->writeln("\$ npm install\n"); exec('npm install'); return; } } }
/** * Sets the application instance for this command. * * Set extra helper ProjectDir * * @param Application $application An Application instance * @throws \Exception * @api */ public function setApplication(Application $application = null) { parent::setApplication($application); if (!$this->getHelperSet()) { throw new \Exception('Helper set is not set.'); } $this->getHelperSet()->set(new SimpleQuestionHelper()); }
public function setApplication(Application $application = NULL) { parent::setApplication($application); $application->setAutoExit(TRUE); /** @var Container $container */ $container = $this->getHelper('container')->getContainer(); $container->callInjects($this); }
private function executeCommand(Command $command, Input $input) { $command->setApplication($this->application); $input->setInteractive(false); if ($command instanceof ContainerAwareCommand) { $command->setContainer($this->client->getContainer()); } $command->run($input, new NullOutput()); }
/** * @param Command $command * @param string[] $arguments * * @return string */ protected function executeConsole(Command $command, array $arguments = array()) { $command->setApplication(new Application($this->client->getKernel())); if ($command instanceof ContainerAwareCommand) { $command->setContainer($this->client->getContainer()); } $arguments = array_replace(array('--env' => 'test', 'command' => $command->getName()), $arguments); $commandTester = new CommandTester($command); $commandTester->execute($arguments); return $commandTester->getDisplay(); }
/** * @param Command $command * @param array|null $systemConfig * @param array|null $localConfig * @param \Closure|null $helperSetManipulator * * @return CommandTester */ protected function getCommandTester(Command $command, array $systemConfig = null, array $localConfig = null, $helperSetManipulator = null) { if (null === $systemConfig) { $systemConfig = ['adapters' => ['github_enterprise' => ['authentication' => ['username' => 'cordoval', 'password' => 'very-un-secret']]]]; } if (null === $localConfig) { $localConfig = self::$localConfig; } if ($this->requiresRealConfigDir()) { $config = new Config($this->getNewTmpDirectory('home'), $systemConfig, $this->getNewTmpDirectory('repo-dir'), $localConfig); } else { try { // Note. The paths must be invalid to always trigger the exception $config = new Config(':?/temp/user', $systemConfig, ':?/temp/repo-dir', $localConfig); } catch (IOException $e) { echo sprintf("Test-class \"%s\" seems to use the filesystem! \nOverwrite requiresRealConfigDir() with 'return " . "true;' to enable the Configuration filesystem usage.", get_class($this)); throw $e; } } $application = $this->getApplication($config, $helperSetManipulator); $command->setApplication($application); return new CommandTester($command); }
/** * Adds a command object. * * If a command with the same name already exists, it will be overridden. * * @param Command $command A Command object * * @return Command The registered command * * @api */ public function add(Command $command) { $command->setApplication($this); if (!$command->isEnabled()) { $command->setApplication(null); return; } if (null === $command->getDefinition()) { throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command))); } $this->commands[$command->getName()] = $command; foreach ($command->getAliases() as $alias) { $this->commands[$alias] = $command; } return $command; }
/** * Adds a command object. * * If a command with the same name already exists, it will be overridden. * * @param Command $command A Command object * * @return Command The registered command * * @api */ public function add(Command $command) { $command->setApplication($this); $this->commands[$command->getName()] = $command; foreach ($command->getAliases() as $alias) { $this->commands[$alias] = $command; } return $command; }
/** * Adds a command object. * * If a command with the same name already exists, it will be overridden. * * @param Command $command A Command object * * @return Command The registered command * * @api */ public function add(Command $command) { $command->setApplication($this); if (!$command->isEnabled()) { $command->setApplication(null); return; } $this->commands[$command->getName()] = $command; foreach ($command->getAliases() as $alias) { $this->commands[$alias] = $command; } return $command; }
/** * {@inheritdoc} */ public function setApplication(Application $application = null) { $this->decoratedCommand->setApplication($application); }
public function setApplication(Application $application = null) { parent::setApplication($application); $this->innerCommand->setApplication($application); }
/** * Run a Symfony command. * * @param Command $command The command to run. * @param array $parameters An array of parameters to give to the command. * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return int The command return code. */ protected function runCommand(Command $command, array $parameters, InputInterface $input, OutputInterface $output) { // add the command's name to the parameters array_unshift($parameters, $this->getName()); // merge the default parameters $extraParameters = ['--verbose' => $input->getOption('verbose')]; if ($command->getDefinition()->hasOption('schema-dir')) { $extraParameters['--schema-dir'] = $this->cacheDir; } if ($command->getDefinition()->hasOption('config-dir')) { $extraParameters['--config-dir'] = $this->cacheDir; } $parameters = array_merge($extraParameters, $parameters); if ($input->hasOption('platform')) { if ($platform = $input->getOption('platform') ?: $this->getPlatform()) { $parameters['--platform'] = $platform; } } $command->setApplication($this->getApplication()); // and run the sub-command return $command->run(new ArrayInput($parameters), $output); }