/** * Push new argument to the end of list of arguments * @param EntityArgument $argument */ public function pushArgument(EntityArgument $argument) { $this->arguments[] = $argument; $argument->setFunction($this); if (!$argument->isOptional()) { $this->required++; } if (Types::$complex[$argument->type]) { $this->info("disable strict mode because of argument {$argument} is complex (type " . Types::getTypeCode($argument->type) . ")"); $this->strict = false; } }
/** * * @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); } }
/** * Generate argument info for method or function * @param EntityArgument $argument * @return string */ private function _arginfo(EntityArgument $argument) { static $types = [Types::BOOLEAN => 'IS_BOOL', Types::STRING => 'IS_STRING', Types::INT => 'IS_LONG', Types::DOUBLE => 'IS_DOUBLE', Types::RESOURCE => 'IS_RESOURCE']; switch ($argument->cast) { case Types::BOOLEAN: case Types::STRING: case Types::INT: case Types::DOUBLE: case Types::RESOURCE: return "ZEND_ARG_TYPE_INFO({$argument->isRef()}, {$argument->name}, {$types[$argument->cast]}, {$argument->allowsNull()})"; case Types::OBJECT: return "ZEND_ARG_OBJ_INFO({$argument->isRef()}, {$argument->name}, \"" . addslashes($argument->instance_of) . "\", {$argument->allowsNull()})"; case Types::ARR: return "ZEND_ARG_ARRAY_INFO({$argument->isRef()}, {$argument->name}, {$argument->allowsNull()})"; default: return "ZEND_ARG_INFO({$argument->isRef()}, {$argument->name})"; } }