isFlag() public method

public isFlag ( )
コード例 #1
0
ファイル: OptionParser.php プロジェクト: c9s/getoptionkit
 /**
  * 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;
 }
コード例 #2
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);
                 }
             }
         }
     }
 }