本文整理汇总了PHP中Symfony\Component\Console\Application::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::has方法的具体用法?PHP Application::has怎么用?PHP Application::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Application
的用法示例。
在下文中一共展示了Application::has方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: match
public function match(Request $request)
{
if (!$request instanceof ConsoleRequest) {
return null;
}
$params = $request->getParams()->toArray();
if (!isset($params[0]) || !$this->application->has($params[0])) {
return null;
}
return new RouteMatch($this->defaults);
}
示例2: testArrayCallbackSyntax
public function testArrayCallbackSyntax()
{
$console = new Application();
$console->add(new LlamaCommand('test:llama-command', null, array($this, 'simpleCallback')));
$this->assertTrue($console->has('test:llama-command'));
$command = $console->get('test:llama-command');
$this->assertInstanceOf('Beryllium\\Llama\\LlamaCommand', $command);
$input = new ArrayInput(array('test:llama-command'));
$output = new BufferedOutput();
$command->run($input, $output);
$this->assertSame("simple callback works\n", $output->fetch());
}
示例3: registerCommands
public function registerCommands(Application $application)
{
/** @var Container $container */
$container = $this->container;
foreach ($container->getServiceIds() as $serviceId) {
$name = null;
if (strncmp($serviceId, "command.", 8) === 0) {
$name = str_replace(".", ":", substr($serviceId, 8));
} elseif (strncmp($serviceId, "task.", 5) === 0) {
$name = str_replace(".", ":", $serviceId);
}
if ($name !== null && !$application->has($name)) {
/** @var Command $command */
$command = $this->container->get($serviceId);
if ($command instanceof AbstractCommand) {
/** @var AbstractCommand $command */
$command->initializeCommand($name);
}
$application->add($command);
}
}
}
示例4: testHasGet
public function testHasGet()
{
$application = new Application();
$this->assertTrue($application->has('list'), '->has() returns true if a named command is registered');
$this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered');
$application->add($foo = new \FooCommand());
$this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered');
$this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name');
$this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias');
$application = new Application();
$application->add($foo = new \FooCommand());
// simulate --help
$r = new \ReflectionObject($application);
$p = $r->getProperty('wantHelps');
$p->setAccessible(true);
$p->setValue($application, true);
$command = $application->get('foo:bar');
$this->assertInstanceOf('Symfony\\Component\\Console\\Command\\HelpCommand', $command, '->get() returns the help command if --help is provided as the input');
}
示例5: testHasGet
public function testHasGet()
{
$application = new Application();
$this->assertTrue($application->has('list'), '->has() returns true if a named command is registered');
$this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered');
$application->add($foo = new \FooCommand());
$this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered');
$this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name');
$this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias');
try {
$application->get('foofoo');
$this->fail('->get() throws an \\InvalidArgumentException if the command does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->get() throws an \\InvalidArgumentException if the command does not exist');
$this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->get() throws an \\InvalidArgumentException if the command does not exist');
}
$application = new TestApplication();
$application->add($foo = new \FooCommand());
$application->setWantHelps();
$command = $application->get('foo:bar');
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($command), '->get() returns the help command if --help is provided as the input');
}
示例6: testDefaultsWithOrm
/**
* @covers ::boot
*/
public function testDefaultsWithOrm()
{
$app = new Silex();
$app['db'] = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
$app['orm.em'] = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$console = new Console();
$app->register(new DoctrineMigrationsProvider($console));
$this->assertFalse($console->has('migrations:execute'));
$this->assertFalse($console->has('migrations:generate'));
$this->assertFalse($console->has('migrations:migrate'));
$this->assertFalse($console->has('migrations:status'));
$this->assertFalse($console->has('migrations:version'));
$this->assertFalse($console->has('migrations:diff'));
$app->boot();
$this->assertTrue($console->has('migrations:execute'));
$this->assertTrue($console->has('migrations:generate'));
$this->assertTrue($console->has('migrations:migrate'));
$this->assertTrue($console->has('migrations:status'));
$this->assertTrue($console->has('migrations:version'));
$this->assertTrue($console->has('migrations:diff'));
}
开发者ID:mikeSimonson,项目名称:silex-doctrine-migrations-provider,代码行数:24,代码来源:DoctrineMigrationsProviderTest.php