Example #1
0
 public function parseReturn(Tokenizer $tokens)
 {
     if ($tokens->valid()) {
         $return = $this->parseExpression($tokens->next());
         dump("{$return}");
         if ($return->isScalar()) {
             switch ($return->type) {
                 case Types::BOOLEAN:
                     return $return->value ? "RETURN_TRUE;" : "RETURN_FALSE;";
                 case Types::DOUBLE:
                     return "RETURN_DOUBLE({$return->value});";
                 case Types::INT:
                     return "RETURN_LONG({$return->value});";
                 case Types::NIL:
                     return "RETURN_NULL();";
                 case Types::STRING:
                     return "RETURN_STRINGL(\"" . addslashes($return->value) . "\", " . strlen($return->value) . ");";
                 default:
                     drop("unknown type " . Types::getTypeCode($return->type));
             }
         } else {
             return "RETURN_ZVAL({$return}, 1);";
         }
     } else {
         return "return;";
     }
 }
Example #2
0
 public function dump($tab = "")
 {
     $args = [];
     foreach ($this->arguments as $arg) {
         $args[] = $arg->dump();
     }
     return static::$entity_type . " {$this->name}(" . ($args ? implode(', ', $args) : '') . '):' . ($this->return_type == -1 ? 'void' : Types::getTypeCode($this->return_type));
 }
Example #3
0
 /**
  * @param object $object
  * @return bool
  * @throws \InvalidArgumentException
  */
 public static function configure($object)
 {
     $options = self::_parse();
     $class = new \ReflectionClass(get_class($object));
     $ce = new EntityClass(get_class($object));
     if (isset($options['help'])) {
         echo "Usage: " . $_SERVER['argv'][0] . " [OPTIONS ...]\nOptions:\n";
         foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
             if (strpos($method->name, 'set') === 0) {
                 $name = substr($method->name, 3);
             } elseif (strpos($method->name, 'get') === 0) {
                 $name = substr($method->name, 3);
             } elseif (strpos($method->name, 'add') === 0) {
                 $name = $method->name;
             } else {
                 continue;
             }
             $name = self::toCLIName($name);
             //				$about = (new EntityMethod($ce->name.'::'.$method->name))->setClass($ce)->scan();
             $about = new EntityMethod($ce->name . '::' . $method->name);
             EntityFile::parseCallable($about, $about->setClass($ce)->getReflection());
             $req = [];
             if ($about->arguments) {
                 $first = true;
                 //					if($about->required == 0) {
                 //						printf("  --%-25s  %s\n", $name, $about->description);
                 //                        $req[] = $name;
                 //					}
                 foreach ($about->arguments as $argument) {
                     $description = $argument->description . ($req ? " (required --" . implode(", --", $req) . ")" : "");
                     /* @var EntityArgument $argument */
                     if ($argument->isOptional()) {
                         if ($first) {
                             $first = false;
                             $arg_name = $name . "[=" . strtoupper($argument->name) . "]";
                             $description = $about->description . sprintf("\n  %-27s  %s — %s", "", strtoupper($argument->name), $argument->description);
                         } else {
                             $arg_name = $name . "." . $argument->name . "=" . strtoupper(Types::getTypeCode($argument->type));
                         }
                         printf("  --%-25s  %s\n", $arg_name, $description);
                     } else {
                         //                            $arg_name = $name.".".$argument->name;
                         if ($first) {
                             $first = false;
                             $arg_name = $name . "=" . strtoupper($argument->name);
                             $description = $about->description . sprintf("\n  %-27s  %s — %s\n", "", strtoupper($argument->name), $argument->description);
                         } else {
                             $arg_name = $name . "." . $argument->name . "=" . strtoupper(Types::getTypeCode($argument->type));
                         }
                         $req[] = $arg_name;
                         printf("  --%-25s  %s\n", $arg_name, $description);
                     }
                 }
             } else {
                 printf("  --%-25s  %s\n", $name, $about->description);
             }
         }
         echo "\nKoda " . \Koda::VERSION_STRING . " by Ivan [Bzick] Shalganov\n";
         return false;
     }
     foreach ($options as $option => $values) {
         $method = str_replace('-', '', $option);
         if (strpos($method, 'add') === 0) {
             self::_call([$object, $method], $values, $option);
         } elseif (method_exists($object, 'set' . $method)) {
             self::_call([$object, 'set' . $method], $values, $option);
         } elseif (method_exists($object, 'get' . $method)) {
             echo self::_call([$object, 'get' . $method], $values, $option) . "\n";
             return false;
         } else {
             throw new \InvalidArgumentException("Unknown option --{$option}");
         }
     }
     return true;
 }