setValue() public method

* set option value
public setValue ( $value )
Example #1
0
 /**
  * consume option value from current argument or from the next argument
  *
  * @return boolean next token consumed?
  */
 protected function consumeOptionToken(Option $spec, $arg, $next, &$success = false)
 {
     // Check options doesn't require next token before
     // all options that require values.
     if ($spec->isFlag()) {
         if ($spec->isIncremental()) {
             $spec->increaseValue();
         } else {
             $spec->setValue(true);
         }
         return 0;
     } else {
         if ($spec->isRequired()) {
             if ($next && !$next->isEmpty() && !$next->anyOfOptions($this->specs)) {
                 $spec->setValue($next->arg);
                 return 1;
             } else {
                 throw new RequireValueException("Option '{$arg->getOptionName()}' requires a value.");
             }
         } else {
             if ($spec->isMultiple()) {
                 if ($next && !$next->isEmpty() && !$next->anyOfOptions($this->specs)) {
                     $this->pushOptionValue($spec, $arg, $next);
                     return 1;
                 }
             } else {
                 if ($spec->isOptional() && $next && !$next->isEmpty() && !$next->anyOfOptions($this->specs)) {
                     $spec->setValue($next->arg);
                     return 1;
                 }
             }
         }
     }
     return 0;
 }
Example #2
0
 public function testFilter()
 {
     $opt = new Option('scope');
     $opt->filter(function ($val) {
         return preg_replace('#a#', 'x', $val);
     });
     $opt->setValue('aa');
     is('xx', $opt->value);
 }
Example #3
0
 public function takeOptionValue(Option $spec, $arg, $next)
 {
     if ($next && !$next->anyOfOptions($this->specs)) {
         $spec->setValue($next->arg);
     } else {
         if ($spec->defaultValue) {
             $spec->setValue($spec->defaultValue);
         } else {
             if ($spec->isFlag()) {
                 $spec->setValue(true);
             } else {
                 if ($next && !$next->isEmpty()) {
                     $spec->setValue($next->arg);
                 } else {
                     $spec->setValue(true);
                 }
             }
         }
     }
 }
Example #4
0
 public function setUp()
 {
     parent::setUp();
     $this->previousPhpBrewRoot = getenv('PHPBREW_ROOT');
     $this->previousPhpBrewHome = getenv('PHPBREW_HOME');
     // <env name="PHPBREW_ROOT" value=".phpbrew"/>
     // <env name="PHPBREW_HOME" value=".phpbrew"/>
     // already setup in phpunit.xml, but it seems don't work.
     putenv('PHPBREW_ROOT=' . getcwd() . '/.phpbrew');
     putenv('PHPBREW_HOME=' . getcwd() . '/.phpbrew');
     if ($options = \PhpBrew\Console::getInstance()->options) {
         $option = new Option('no-progress');
         $option->setValue(true);
         $options->set('no-progress', $option);
     }
 }