本文整理汇总了PHP中Symfony\Component\Console\Application::findNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::findNamespace方法的具体用法?PHP Application::findNamespace怎么用?PHP Application::findNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Application
的用法示例。
在下文中一共展示了Application::findNamespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inspectApplication
private function inspectApplication()
{
$this->commands = array();
$this->namespaces = array();
$all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
foreach ($this->sortCommands($all) as $namespace => $commands) {
$names = array();
/** @var Command $command */
foreach ($commands as $name => $command) {
if (!$command->getName()) {
continue;
}
if ($command->getName() === $name) {
$this->commands[$name] = $command;
} else {
$this->aliases[$name] = $command;
}
$names[] = $name;
}
$this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
}
}
示例2: testFindInvalidNamespace
/**
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
*/
public function testFindInvalidNamespace()
{
$application = new Application();
$application->findNamespace('bar');
}
示例3: testFindNamespace
public function testFindNamespace()
{
$application = new Application();
$application->add(new \FooCommand());
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
$this->assertEquals('foo', $application->findNamespace('f'), '->findNamespace() finds a namespace given an abbreviation');
$application->add(new \Foo2Command());
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
try {
$application->findNamespace('f');
$this->fail('->findNamespace() throws an \\InvalidArgumentException if the abbreviation is ambiguous');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->findNamespace() throws an \\InvalidArgumentException if the abbreviation is ambiguous');
$this->assertEquals('The namespace "f" is ambiguous (foo, foo1).', $e->getMessage(), '->findNamespace() throws an \\InvalidArgumentException if the abbreviation is ambiguous');
}
try {
$application->findNamespace('bar');
$this->fail('->findNamespace() throws an \\InvalidArgumentException if no command is in the given namespace');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->findNamespace() throws an \\InvalidArgumentException if no command is in the given namespace');
$this->assertEquals('There are no commands defined in the "bar" namespace.', $e->getMessage(), '->findNamespace() throws an \\InvalidArgumentException if no command is in the given namespace');
}
}