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

For options with values, you can pass the value in the second argument. The value is converted to the type defined by the argument format. For options without values, you can omit the second argument. Optionally, you can pass true/false explicitly to enable/disable the option.
public setOption ( string $name, mixed $value = true ) : static
$name string The long or short option name.
$value mixed The value to set for the option.
Результат static The current instance.
Пример #1
0
 /**
  * Creates the arguments from the current class state.
  *
  * @param ArgsFormat $format  The format.
  * @param RawArgs    $rawArgs The raw arguments.
  *
  * @return Args The created console arguments.
  */
 private function createArgs(ArgsFormat $format, RawArgs $rawArgs)
 {
     $args = new Args($format, $rawArgs);
     foreach ($this->arguments as $name => $value) {
         // Filter command names
         if ($format->hasArgument($name)) {
             $args->setArgument($name, $value);
         }
     }
     foreach ($this->options as $name => $value) {
         // Filter command options
         if ($format->hasOption($name)) {
             $args->setOption($name, $value);
         }
     }
     return $args;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function setOption($name, $value)
 {
     if ($this->args) {
         $this->args->setOption($name, $value);
     }
 }
Пример #3
0
 public function testIsOptionSetReturnsFalseAfterSettingToFalse()
 {
     $format = ArgsFormat::build()->addOption(new Option('option'))->getFormat();
     $args = new Args($format);
     $args->setOption('option');
     $args->setOption('option', false);
     $this->assertFalse($args->isOptionSet('option'));
 }