當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::addCommand方法代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Application::addCommand方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::addCommand方法的具體用法?PHP Application::addCommand怎麽用?PHP Application::addCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Console\Application的用法示例。


在下文中一共展示了Application::addCommand方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: registerCommands

 /**
  * Finds and registers Commands.
  *
  * @param Application $application An Application instance
  */
 public function registerCommands(Application $application)
 {
     if (!($dir = realpath($this->getPath() . '/Command'))) {
         return;
     }
     $finder = new Finder();
     $finder->files()->name('*Command.php')->in($dir);
     $prefix = $this->namespacePrefix . '\\' . $this->name . '\\Command';
     foreach ($finder as $file) {
         $r = new \ReflectionClass($prefix . strtr($file->getPath(), array($dir => '', '/' => '\\')) . '\\' . basename($file, '.php'));
         if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
             $application->addCommand($r->newInstance());
         }
     }
 }
開發者ID:skoop,項目名稱:symfony-sandbox,代碼行數:20,代碼來源:Bundle.php

示例2: testRun

 public function testRun()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $application->addCommand($command = new \Foo1Command());
     $_SERVER['argv'] = array('cli.php', 'foo:bar1');
     ob_start();
     $application->run();
     ob_end_clean();
     $this->assertEquals('Symfony\\Component\\Console\\Input\\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
     $this->assertEquals('Symfony\\Component\\Console\\Output\\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array());
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run1.txt', $tester->getDisplay(), '->run() runs the list command if no argument is passed');
     $tester->run(array('--help' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $tester->getDisplay(), '->run() runs the help command if --help is passed');
     $tester->run(array('-h' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $tester->getDisplay(), '->run() runs the help command if -h is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array('command' => 'list', '--help' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $tester->getDisplay(), '->run() displays the help if --help is passed');
     $tester->run(array('command' => 'list', '-h' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $tester->getDisplay(), '->run() displays the help if -h is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array('--ansi' => true));
     $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
     $tester->run(array('-a' => true));
     $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if -a is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array('--version' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $tester->getDisplay(), '->run() displays the program version if --version is passed');
     $tester->run(array('-V' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $tester->getDisplay(), '->run() displays the program version if -v is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array('command' => 'list', '--quiet' => true));
     $this->assertEquals('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');
     $tester->run(array('command' => 'list', '-q' => true));
     $this->assertEquals('', $tester->getDisplay(), '->run() removes all output if -q is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array('command' => 'list', '--verbose' => true));
     $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is --verbose is passed');
     $tester->run(array('command' => 'list', '-v' => true));
     $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is -v is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $application->addCommand(new \FooCommand());
     $tester = new ApplicationTester($application);
     $tester->run(array('command' => 'foo:bar', '--no-interaction' => true));
     $this->assertEquals("called\n", $tester->getDisplay(), '->run() does not called interact() if --no-interaction is passed');
     $tester->run(array('command' => 'foo:bar', '-n' => true));
     $this->assertEquals("called\n", $tester->getDisplay(), '->run() does not called interact() if -n is passed');
 }
開發者ID:netixpro,項目名稱:symfony,代碼行數:72,代碼來源:ApplicationTest.php


注:本文中的Symfony\Component\Console\Application::addCommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。