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