本文整理汇总了PHP中Symfony\Component\Console\Application::setDispatcher方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::setDispatcher方法的具体用法?PHP Application::setDispatcher怎么用?PHP Application::setDispatcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Application
的用法示例。
在下文中一共展示了Application::setDispatcher方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple\Container $container A container instance
*/
public function register(Container $container)
{
$container['console.name'] = 'Console';
$container['console.version'] = '1.0';
$container['console.event_dispatcher'] = null;
$container['console.enable_xdebug'] = false;
$container['console'] = function (Container $container) {
$console = new ConsoleApplication($container['console.name'], $container['console.version']);
if ($container['console.enable_xdebug'] && function_exists('xdebug_enable')) {
$definition = $console->getDefinition();
$definition->addOption(new InputOption('debug', null, InputOption::VALUE_NONE, 'Enable XDebug jit remote mode'));
$console->setDefinition($definition);
foreach ($_SERVER['argv'] as $arg) {
if ('--debug' === $arg) {
poke_xdebug();
break;
} elseif ('--' === $arg) {
break;
}
}
}
$dispatcher = $container['console.event_dispatcher'];
if (is_string($dispatcher)) {
$dispatcher = $container[$dispatcher];
}
if ($dispatcher instanceof EventDispatcherInterface) {
$console->setDispatcher($dispatcher);
$dispatcher->dispatch(Events::INIT, new InitializeConsoleEvent($console));
}
return $console;
};
}
示例2: runTest
public function runTest()
{
$dispatcher = $this->dispatcher = new EventDispatcher();
$application = new Application();
$application->setAutoExit(false);
$application->setDispatcher($dispatcher);
$this->testOne();
$this->testTwo();
$application->run();
}
示例3: run
public function run()
{
$console = new Application(self::APP_NAME, self::APP_VERSION);
$console->setDefaultCommand(self::APP_DEFAULT_COMMAND);
$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
// get the input instance
// $input = $event->getInput();
// get the output instance
$output = $event->getOutput();
// get the command to be executed
$command = $event->getCommand();
// write something about the command
//$output->writeln(sprintf('Before running command <info>%s</info>', $command->getName()));
if ($command->getName() == StartServer::CLI_COMMAND) {
$output->write(self::$BANNER);
}
// get the application
// $application = $command->getApplication();
});
$console->setDispatcher($dispatcher);
$console->addCommands([new Controller\StartServer(), new Controller\StopServer(), new Controller\ListServers(), new Controller\RegisterServer()]);
$console->run();
}
示例4: testRunWithDispatcherAddingInputOptions
public function testRunWithDispatcherAddingInputOptions()
{
$extraValue = null;
$dispatcher = $this->getDispatcher();
$dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use(&$extraValue) {
$definition = $event->getCommand()->getDefinition();
$input = $event->getInput();
$definition->addOption(new InputOption('extra', null, InputOption::VALUE_REQUIRED));
$input->bind($definition);
$extraValue = $input->getOption('extra');
});
$application = new Application();
$application->setDispatcher($dispatcher);
$application->setAutoExit(false);
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('foo.');
});
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo', '--extra' => 'some test value'));
$this->assertEquals('some test value', $extraValue);
}
示例5: Application
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
$console = new Application('Artsper Backoffice', 'n/a');
$console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
$console->setDispatcher($app['dispatcher']);
$console->register('my-command')->setDefinition(array())->setDescription('My command description')->setCode(function (InputInterface $input, OutputInterface $output) use($app) {
// do something
});
return $console;
示例6: testRunWithDispatcherSkippingCommand
public function testRunWithDispatcherSkippingCommand()
{
$application = new Application();
$application->setDispatcher($this->getDispatcher(true));
$application->setAutoExit(false);
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('foo.');
});
$tester = new ApplicationTester($application);
$exitCode = $tester->run(array('command' => 'foo'));
$this->assertContains('before.after.', $tester->getDisplay());
$this->assertEquals(ConsoleCommandEvent::RETURN_CODE_DISABLED, $exitCode);
}
示例7: testRunDispatchesAllEventsWithException
public function testRunDispatchesAllEventsWithException()
{
if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
$application = new Application();
$application->setDispatcher($this->getDispatcher());
$application->setAutoExit(false);
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('foo.');
throw new \RuntimeException('foo');
});
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'));
$this->assertContains('before.foo.after.caught.', $tester->getDisplay());
}
示例8: testRunDispatchesAllEventsWithException
public function testRunDispatchesAllEventsWithException()
{
$application = new Application();
$application->setDispatcher($this->getDispatcher());
$application->setAutoExit(false);
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('foo.');
throw new \RuntimeException('foo');
});
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'));
$this->assertContains('before.foo.after.caught.', $tester->getDisplay());
}
示例9: Application
$container = \DG\App\loadContainer();
$eventDispatcher = $container->get('event_dispatcher.traceable');
$app = new Application();
$app->add(new MakesCacheCommand($container));
$app->add(new CssSelectorTestCommand());
$app->add($reportCommand = new MakesCacheReportCommand());
$app->add(new DomCrawlerTestCommand());
$app->add(new DomCrawlerHHTestCommand());
$app->add(new ExpressionLanguageCommand());
$app->add(new LockHandlerTestCommand());
$app->add(new IntlTestCommand());
$app->add(new ModelsCommand($container));
$app->add(new ProcessCommand());
$app->add(new TestTimingAttackCommand());
$app->setDefaultCommand($reportCommand->getName());
$app->setDispatcher($eventDispatcher);
$eventDispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) use($reportCommand) {
$output = $event->getOutput();
$output->writeln("<info>Run command " . $event->getCommand()->getName() . "</info>");
if ($event->getCommand() instanceof MakesCacheReportCommand) {
$finder = new Finder();
$makesCacheFilesCount = $finder->in(CACHE_PATH)->name('makes*.json')->count();
if ($makesCacheFilesCount === 0 && $event->getCommand()->getName() === $reportCommand->getName()) {
$output->writeln("<error>There is no cache files. Command execution stopped</error>");
$event->disableCommand();
}
}
});
$eventDispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
//wrap exception
});
示例10: Config
return new Config($c['compose.project']);
};
$container['command.run'] = function ($c) {
return new RunCommand($c['process.interactive_runner'], $c['compose.config']);
};
$container['event_dispatcher'] = function () {
return new EventDispatcher();
};
$container['logs'] = function ($c) {
return new Logs($c['compose.executable_finder'], $c['process.silent_runner']);
};
$container['doctor.tasks'] = function ($c) {
return [new Doctor\Docker($c['process.silent_runner'], new Doctor\Action\StartMachineOrInstall($c['machine'], $c['installer.docker']), $c['installer.docker']), new Doctor\DnsDock($c['process.silent_runner'], $c['installer.dns.dnsdock'], $c['installer.dns.docker_routing'])];
};
$container['application'] = function ($c) {
$application = new Application('Dock CLI', '@package_version@');
$application->setDispatcher($c['event_dispatcher']);
$application->addCommands([$c['command.selfupdate'], $c['command.doctor'], $c['command.install'], $c['command.restart'], $c['command.run'], $c['command.start'], $c['command.stop'], $c['command.build'], $c['command.reset'], $c['command.ps'], $c['command.logs']]);
return $application;
};
$osDetector = new OperatingSystemDetector();
if ($osDetector->isMac()) {
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'container.mac.php';
} elseif ($osDetector->isDebian()) {
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'container.debian.php';
} elseif ($osDetector->isRedHat()) {
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'container.redhat.php';
} else {
throw new \Exception($osDetector->isLinux() ? "Installer does not support linux distribution: " . $osDetector->getLinuxDistribution() : "Installer does not support operating system: " . $osDetector->getOperatingSystem());
}
return $container;
示例11: assertRunCommandViaApplicationEquals
function assertRunCommandViaApplicationEquals($command, $input, $expectedOutput, $expectedStatusCode = 0)
{
$output = new BufferedOutput();
if ($this->commandFileInstance && method_exists($this->commandFileInstance, 'setOutput')) {
$this->commandFileInstance->setOutput($output);
}
$application = new Application('TestApplication', '0.0.0');
$alterOptionsEventManager = new AlterOptionsCommandEvent($application);
$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addSubscriber($this->commandFactory->commandProcessor()->hookManager());
$eventDispatcher->addSubscriber($alterOptionsEventManager);
$application->setDispatcher($eventDispatcher);
$application->setAutoExit(false);
$application->add($command);
$statusCode = $application->run($input, $output);
$commandOutput = trim($output->fetch());
$this->assertEquals($expectedOutput, $commandOutput);
$this->assertEquals($expectedStatusCode, $statusCode);
}
示例12: createConsole
/**
* Creates an instance of Console App
* @return ConsoleApplication
*/
public function createConsole()
{
$console = new ConsoleApplication($this['app.console_name']);
$envOption = new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev');
$console->getDefinition()->addOption($envOption);
$console->setDispatcher($this['dispatcher']);
return $console;
}
示例13: registerConsole
/**
* {@inheritdoc}
*/
public function registerConsole(Application $console)
{
$eventDispatcher = $this->app->getContainer()->resolve('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$console->setDispatcher($eventDispatcher);
}