当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::setDispatcher方法代码示例

本文整理汇总了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;
     };
 }
开发者ID:jonsa,项目名称:pimple-console,代码行数:40,代码来源:ServiceProvider.php

示例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();
 }
开发者ID:jeanpasqualini-lesson,项目名称:lesson-console,代码行数:10,代码来源:EventCommandTest.php

示例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();
 }
开发者ID:bogdananton,项目名称:selenium-setup,代码行数:24,代码来源:SeleniumSetup.php

示例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);
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:21,代码来源:ApplicationTest.php

示例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;
开发者ID:streetcolor,项目名称:silex-mvc,代码行数:14,代码来源:console.php

示例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);
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:13,代码来源:ApplicationTest.php

示例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());
 }
开发者ID:richsage,项目名称:symfony,代码行数:16,代码来源:ApplicationTest.php

示例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());
 }
开发者ID:peintune,项目名称:Ternado,代码行数:13,代码来源:ApplicationTest.php

示例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
 });
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:31,代码来源:console.php

示例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;
开发者ID:Elfiggo,项目名称:dock-cli,代码行数:31,代码来源:container.php

示例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);
 }
开发者ID:consolidation,项目名称:annotated-command,代码行数:19,代码来源:testAnnotatedCommandFactory.php

示例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;
 }
开发者ID:vudaltsov,项目名称:silex-project,代码行数:12,代码来源:Application.php

示例13: registerConsole

 /**
  * {@inheritdoc}
  */
 public function registerConsole(Application $console)
 {
     $eventDispatcher = $this->app->getContainer()->resolve('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $console->setDispatcher($eventDispatcher);
 }
开发者ID:autarky,项目名称:framework,代码行数:8,代码来源:EventDispatcherProvider.php


注:本文中的Symfony\Component\Console\Application::setDispatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。