本文整理汇总了PHP中Symfony\Component\Console\Input\InputDefinition::getArgument方法的典型用法代码示例。如果您正苦于以下问题:PHP InputDefinition::getArgument方法的具体用法?PHP InputDefinition::getArgument怎么用?PHP InputDefinition::getArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\InputDefinition
的用法示例。
在下文中一共展示了InputDefinition::getArgument方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getArgument
/**
* Returns the argument value for a given argument name.
*
* @param string $name The argument name
*
* @return mixed The argument value
*
* @throws InvalidArgumentException When argument given doesn't exist
*/
public function getArgument($name)
{
if (!$this->definition->hasArgument($name)) {
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
}
return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
}
示例2: setArgumentDescription
private function setArgumentDescription(InputDefinition $definition, $name, $description)
{
$argument = $definition->getArgument($name);
if ($argument instanceof InputArgument) {
$argument->setDescription($description);
}
}
示例3: testGetInvalidArgument
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "bar" argument does not exist.
*/
public function testGetInvalidArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArguments(array($this->foo));
$definition->getArgument('bar');
}
示例4: testGetArgument
public function testGetArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArguments(array($this->foo));
$this->assertEquals($this->foo, $definition->getArgument('foo'), '->getArgument() returns a InputArgument by its name');
try {
$definition->getArgument('bar');
$this->fail('->getArgument() throws an exception if the InputArgument name does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\\Exception', $e, '->getArgument() throws an exception if the InputArgument name does not exist');
$this->assertEquals('The "bar" argument does not exist.', $e->getMessage());
}
}