本文整理汇总了PHP中Option::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::getName方法的具体用法?PHP Option::getName怎么用?PHP Option::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::getName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: offsetSet
/**
* Set a new option.
*
* @param string $name No use here, we use option name.
* @param Option $option The option object to set in this set.
*
* @return void
*
* @since 1.0
*/
public function offsetSet($name, $option)
{
$name = $option->getName();
$aliases = $option->getAlias();
$this->setAlias($aliases, $name);
parent::offsetSet($name, $option);
}
示例2: addOption
/**
* @param string|Option $name
* @param float|null $price
* @param StockItem|null $item
*/
public function addOption($name, $price = null, StockItem $item = null)
{
if (!$name instanceof Option) {
$name = (string) $name;
if (empty($name)) {
throw new \InvalidArgumentException('option name cannot be empty');
}
$name = new Option($name, $price, $item);
unset($price, $item);
}
if (null !== $this->_findOption($name->getName()) || in_array($name->getStockItem(), $this->_getStockItems(), true)) {
throw new \InvalidArgumentException('cannot add option with the same name twice');
}
$this->options[] = $name;
}
示例3: registerOption
protected function registerOption(Option $opt)
{
$registered = FALSE;
foreach (array('short', 'long') as $prefix) {
if (($name = $opt->{'get' . lcfirst($prefix) . 'Name'}()) === NULL) {
continue;
}
$registered = TRUE;
if (isset($this->{$prefix . 'Opts'}[$name])) {
throw new OptionAlreadyRegisteredException($name, $prefix === 'long');
}
$this->{$prefix . 'Opts'}[$name] = $opt;
}
if ($registered === FALSE) {
throw new InvalidArgumentException("Either short or long option name must be set for option '{$opt->getName()}'.");
}
}
示例4: offsetSet
/**
* Set a new option.
*
* @param string $name No use here, we use option name.
* @param Option $option The option object to set in this set.
*
* @return void
*
* @since 2.0
*/
public function offsetSet($name, $option)
{
$name = $option->getName();
$this->options[$name] = $option;
}
示例5: triggerOption
/**
* @param $option
* @param string $value
*/
public function triggerOption(Option $option, $value = '')
{
if ($option->getName() == 'help') {
$this->outputHelp();
} elseif ($option->getName() == 'version') {
$this->outputVersion();
} else {
$this->createProperty($option->getName(), $value);
}
}
示例6: addOption
/**
* 添加一个选项
* @param Option $option 选项
* @throws \LogicException
* @api
*/
public function addOption(Option $option)
{
if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
}
if ($option->getShortcut()) {
foreach (explode('|', $option->getShortcut()) as $shortcut) {
if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
throw new \LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
}
}
}
$this->options[$option->getName()] = $option;
if ($option->getShortcut()) {
foreach (explode('|', $option->getShortcut()) as $shortcut) {
$this->shortcuts[$shortcut] = $option->getName();
}
}
}
示例7: testGetName
/**
* @covers Phossa\Console\Option::getName
*/
public function testGetName()
{
$this->assertEquals('user', $this->object->getName());
}
示例8: addOption
/**
* Add an Option object.
*
* @param Option $option An Option object
*/
public function addOption(Option $option)
{
if (isset($this->options[$option->getName()])) {
throw new \LogicException(sprintf('An option named "%s" already exist.', $option->getName()));
} else {
if (isset($this->shortcuts[$option->getShortcut()])) {
throw new \LogicException(sprintf('An option with shortcut "%s" already exist.', $option->getShortcut()));
}
}
$this->options[$option->getName()] = $option;
if ($option->getShortcut()) {
$this->shortcuts[$option->getShortcut()] = $option->getName();
}
}
示例9: equals
/**
* 检查所给选项是否是当前这个
* @param Option $option
* @return bool
*/
public function equals(Option $option)
{
return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() && $option->getDefault() === $this->getDefault() && $option->isArray() === $this->isArray() && $option->isValueRequired() === $this->isValueRequired() && $option->isValueOptional() === $this->isValueOptional();
}
示例10: Option
function test_getIdsFromNames()
{
//arrange
$name = "peanut-free";
$test_option = new Option($name);
$test_option->save();
$name2 = "soy-free";
$test_option2 = new Option($name2);
$test_option2->save();
//act
$suitable_options_names = array($test_option->getName(), $test_option2->getName());
$result = Option::getIdsFromNames($suitable_options_names);
//assert
$this->assertEquals([$test_option->getId(), $test_option2->getId()], $result);
}