Exemplo n.º 1
0
 /**
  *
  * @param EntityFunction $callable
  * @param \ReflectionFunctionAbstract $reflection
  * @return $this
  */
 public static function parseCallable(EntityFunction $callable, \ReflectionFunctionAbstract $reflection)
 {
     $doc = $reflection->getDocComment();
     $params = [];
     if ($doc) {
         $info = ToolKit::parseDoc($doc);
         $callable->setDescription($info['desc']);
         $callable->setReturnInfo($info['return']['type'], $reflection->returnsReference(), $info['return']['desc']);
         $callable->setOptions($info['options']);
         $params = $info["params"];
     } else {
         $info = [];
     }
     /* @var \ReflectionParameter[] $params */
     foreach ($reflection->getParameters() as $param) {
         $argument = new EntityArgument($param->name);
         if (isset($params[$param->name]["desc"])) {
             $argument->description = $params[$param->name]["desc"];
         }
         if ($callable->getLine()) {
             $argument->setLine($callable->getLine());
         }
         $argument->setOptional($param->isOptional());
         $argument->setNullAllowed($param->allowsNull());
         $argument->setValue($param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->isPassedByReference());
         $argument->setByRef($param->isPassedByReference());
         /** @var \ReflectionParameter $param */
         if ($param->isArray()) {
             $argument->setCast(Types::ARR);
         }
         if ($c = $param->getClass()) {
             $argument->setCast(Types::OBJECT, $c->name);
         } elseif (isset($info['params'][$param->name])) {
             $_type = $info['params'][$param->name]["type"];
             if (strpos($_type, "|") || $_type === "mixed") {
                 // multiple types or mixed
                 $argument->setCast(Types::MIXED);
             } else {
                 if (strpos($_type, "[]")) {
                     $argument->setCast(Types::ARR, rtrim($_type, '[]'));
                 }
                 if (isset(Types::$codes[$_type])) {
                     $argument->setCast(Types::getType($_type));
                 } else {
                     $argument->setCast(Types::OBJECT, ltrim($_type, '\\'));
                 }
             }
         } else {
             $argument->warning("not documented");
         }
         $callable->pushArgument($argument);
     }
 }
Exemplo n.º 2
0
 public function dump($tab = "")
 {
     return parent::dump($tab) . "  [" . Flags::decode($this->flags) . "]";
 }