Esempio n. 1
0
 public function validateValues()
 {
     $return = array();
     // do we have any arguments at all?
     if (!$this->definition->testHasArgument()) {
         // no, so impossible to fail validation
         return $return;
     }
     // are all the arguments valid?
     foreach ($this->values as $value) {
         $errors = $this->definition->arg->testIsValid($value);
         if (count($errors) > 0) {
             $return = array_merge($return, $errors);
         }
     }
     // all done
     return $return;
 }
 protected function parseArgument($args, $argIndex, $startFrom, DefinedSwitch $switch, $switchSeen)
 {
     // initialise the return value
     $arg = null;
     // is the argument optional or required?
     if ($switch->testHasOptionalArgument()) {
         // it is optional ... but is
         // it there?
         if (isset($args[$argIndex])) {
             // yes it is
             $arg = substr($args[$argIndex], $startFrom);
         } else {
             $arg = $switch->arg->defaultValue;
             $argIndex--;
         }
     } else {
         // argument is required ... but
         // is it there?
         if (!isset($args[$argIndex])) {
             // no it is not
             // error!
             throw new \Exception('switch ' . $switchSeen . ' expected argument');
         }
         // yes it is
         $arg = substr($args[$argIndex], $startFrom);
         // did we get an argument?
         if (strlen(trim($arg)) == 0) {
             // no, we did not
             throw new \Exception('switch ' . $switchSeen . ' expected argument');
         }
     }
     return array($arg, $argIndex);
 }