當前位置: 首頁>>代碼示例>>PHP>>正文


PHP InputOption::isValueOptional方法代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Input\InputOption::isValueOptional方法的典型用法代碼示例。如果您正苦於以下問題:PHP InputOption::isValueOptional方法的具體用法?PHP InputOption::isValueOptional怎麽用?PHP InputOption::isValueOptional使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Console\Input\InputOption的用法示例。


在下文中一共展示了InputOption::isValueOptional方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testConstructor

 public function testConstructor()
 {
     $option = new InputOption('foo');
     $this->assertEquals('foo', $option->getName(), '__construct() takes a name as its first argument');
     $option = new InputOption('--foo');
     $this->assertEquals('foo', $option->getName(), '__construct() removes the leading -- of the option name');
     try {
         $option = new InputOption('foo', 'f', InputOption::VALUE_IS_ARRAY);
         $this->fail('->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
         $this->assertEquals('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.', $e->getMessage());
     }
     // shortcut argument
     $option = new InputOption('foo', 'f');
     $this->assertEquals('f', $option->getShortcut(), '__construct() can take a shortcut as its second argument');
     $option = new InputOption('foo', '-f');
     $this->assertEquals('f', $option->getShortcut(), '__construct() removes the leading - of the shortcut');
     $option = new InputOption('foo');
     $this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
     // mode argument
     $option = new InputOption('foo', 'f');
     $this->assertFalse($option->acceptValue(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $this->assertFalse($option->isValueRequired(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $this->assertFalse($option->isValueOptional(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $option = new InputOption('foo', 'f', null);
     $this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
     $this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_REQUIRED);
     $this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $this->assertTrue($option->isValueRequired(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL);
     $this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     $this->assertTrue($option->isValueOptional(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     try {
         $option = new InputOption('foo', 'f', 'ANOTHER_ONE');
         $this->fail('__construct() throws an Exception if the mode is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '__construct() throws an Exception if the mode is not valid');
         $this->assertEquals('Option mode "ANOTHER_ONE" is not valid.', $e->getMessage());
     }
     try {
         $option = new InputOption('foo', 'f', -1);
         $this->fail('__construct() throws an Exception if the mode is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '__construct() throws an Exception if the mode is not valid');
         $this->assertEquals('Option mode "-1" is not valid.', $e->getMessage());
     }
 }
開發者ID:laiello,項目名稱:masfletes,代碼行數:56,代碼來源:InputOptionTest.php

示例2: getOptionMode

 /**
  * @param InputOption $option
  * @return int
  */
 private function getOptionMode(InputOption $option)
 {
     $mode = 0;
     if ($option->isArray()) {
         $mode |= InputOption::VALUE_IS_ARRAY;
     }
     if ($option->isValueOptional()) {
         $mode |= InputOption::VALUE_OPTIONAL;
     }
     if ($option->isValueRequired()) {
         $mode |= InputOption::VALUE_REQUIRED;
     }
     if (!$mode) {
         $mode = InputOption::VALUE_NONE;
     }
     return $mode;
 }
開發者ID:brainexe,項目名稱:core,代碼行數:21,代碼來源:ConsoleCompilerPass.php

示例3: describeInputOption

 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
         $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($option->getDefault()));
     } else {
         $default = '';
     }
     $value = '';
     if ($option->acceptValue()) {
         $value = '=' . strtoupper($option->getName());
         if ($option->isValueOptional()) {
             $value = '[' . $value . ']';
         }
     }
     $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions(array($option));
     $synopsis = sprintf('%s%s', $option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : '    ', sprintf('--%s%s', $option->getName(), $value));
     $spacingWidth = $totalWidth - strlen($synopsis) + 2;
     $this->writeText(sprintf('  <info>%s</info>%s%s%s%s', $synopsis, str_repeat(' ', $spacingWidth), preg_replace('/\\s*[\\r\\n]\\s*/', "\n" . str_repeat(' ', $totalWidth + 17), $option->getDescription()), $default, $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''), $options);
 }
開發者ID:JesseDarellMoore,項目名稱:CS499,代碼行數:22,代碼來源:TextDescriptor.php

示例4: testModes

 public function testModes()
 {
     $option = new InputOption('foo', 'f');
     $this->assertFalse($option->acceptValue(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $this->assertFalse($option->isValueRequired(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $this->assertFalse($option->isValueOptional(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $option = new InputOption('foo', 'f', null);
     $this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
     $this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_REQUIRED);
     $this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $this->assertTrue($option->isValueRequired(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL);
     $this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     $this->assertTrue($option->isValueOptional(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
 }
開發者ID:mawaha,項目名稱:tracker,代碼行數:23,代碼來源:InputOptionTest.php

示例5: equals

 /**
  * Checks whether the given option equals this one.
  *
  * @param InputOption $option option to compare
  *
  * @return bool
  */
 public function equals(InputOption $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();
 }
開發者ID:saj696,項目名稱:pipe,代碼行數:11,代碼來源:InputOption.php


注:本文中的Symfony\Component\Console\Input\InputOption::isValueOptional方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。