think\console\input\Option::isValueOptional PHP Метод

isValueOptional() публичный Метод

是否可选
public isValueOptional ( ) : boolean
Результат boolean 类型是 self::VALUE_OPTIONAL 的时候返回true,其他均返回false
    public function isValueOptional()
    {
        return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
    }

Usage Example

Пример #1
0
 /**
  * 描述选项
  * @param InputOption $option
  * @param array       $options
  * @return string|mixed
  */
 protected function describeInputOption(InputOption $option, array $options = [])
 {
     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([$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\\s*/', "\n" . str_repeat(' ', $totalWidth + 17), $option->getDescription()), $default, $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''), $options);
 }