本文整理汇总了PHP中Symfony\Component\Console\Command\Command::setApplication方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::setApplication方法的具体用法?PHP Command::setApplication怎么用?PHP Command::setApplication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Command\Command
的用法示例。
在下文中一共展示了Command::setApplication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wrapCommand
/**
* @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;
}
示例2: testConsoleEvent
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());
}
示例3: setApplication
/**
* 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);
}
示例4: postInstall
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;
}
}
}
示例5: setApplication
/**
* 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());
}
示例6: setApplication
public function setApplication(Application $application = NULL)
{
parent::setApplication($application);
$application->setAutoExit(TRUE);
/** @var Container $container */
$container = $this->getHelper('container')->getContainer();
$container->callInjects($this);
}
示例7: executeCommand
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());
}
示例8: executeConsole
/**
* @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();
}
示例9: getCommandTester
/**
* @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);
}
示例10: add
/**
* 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;
}
示例11: add
/**
* 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;
}
示例12: add
/**
* 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;
}
示例13: setApplication
/**
* {@inheritdoc}
*/
public function setApplication(Application $application = null)
{
$this->decoratedCommand->setApplication($application);
}
示例14: setApplication
public function setApplication(Application $application = null)
{
parent::setApplication($application);
$this->innerCommand->setApplication($application);
}
示例15: runCommand
/**
* 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);
}