本文整理汇总了PHP中Reflector::getReflectionFunctionForCallable方法的典型用法代码示例。如果您正苦于以下问题:PHP Reflector::getReflectionFunctionForCallable方法的具体用法?PHP Reflector::getReflectionFunctionForCallable怎么用?PHP Reflector::getReflectionFunctionForCallable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reflector
的用法示例。
在下文中一共展示了Reflector::getReflectionFunctionForCallable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRouteDefinition
/**
* @param $route
* @return array
*/
private function addRouteDefinition(\DC\Router\IRoute $route)
{
$path = $this->simplifyPathForSwagger($route->getPath());
$method = strtolower($route->getMethod());
$callable = $route->getCallable();
$reflection = $this->reflector->getReflectionFunctionForCallable($callable);
if ($reflection instanceof \ReflectionMethod) {
if (!$reflection->getDeclaringClass()->implementsInterface('\\DC\\Router\\Swagger\\ISwaggerAPI')) {
return;
}
}
$phpdoc = new \phpDocumentor\Reflection\DocBlock($reflection);
if (count($phpdoc->getTagsByName(SwaggerExcludeTag::$name)) > 0) {
return;
}
$routeDef = ["produces" => ["application/json"], "responses" => []];
if ($method == "post" || $method == "put") {
$routeDef["consumes"] = ["application/json"];
}
if ($reflection instanceof \ReflectionMethod) {
$reflectionClass = $reflection->getDeclaringClass();
$routeDef["tags"] = [$this->addTagForController($reflectionClass)];
}
$parameters = $this->routeMatcher->getParameterInfo($route);
$paramTags = $phpdoc->getTagsByName("param");
$reflectionParameters = $reflection->getParameters();
$reflectionParametersByName = [];
foreach ($reflectionParameters as $parameter) {
$reflectionParametersByName[$parameter->getName()] = $parameter;
}
foreach ($parameters as $parameter) {
$matchingParamTags = array_filter($paramTags, function ($t) use($parameter) {
return $t->getVariableName() == '$' . $parameter->getInternalName();
});
$paramTag = reset($matchingParamTags);
$reflectionParameter = $reflectionParametersByName[$parameter->getInternalName()];
$required = !isset($reflectionParameter) || !$reflectionParameter->isOptional();
$paramDef = ["name" => $parameter->getQueryName(), "in" => $parameter->getPlacement(), "required" => $required];
if ($paramTag != null) {
$paramDef["description"] = $paramTag->getDescription();
$paramDef += $this->getTypeDefinition($paramTag->getType());
} else {
$paramDef["type"] = "string";
}
$routeDef["parameters"][] = $paramDef;
}
/**
* @var $returnTag \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag[]
*/
$returnTag = $phpdoc->getTagsByName("return");
if (count($returnTag) > 0) {
$returnTypes = $returnTag[0]->getTypes();
if (!isset($returnTypes)) {
$returnTypes = [$returnTag[0]->getType()];
}
foreach ($returnTypes as $type) {
$defRef = $this->getTypeDefinitionOrReference($type);
$routeDef["responses"][200] = ["schema" => $defRef, "description" => $returnTag[0]->getDescription()];
}
}
/** @var $throwsTags \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag[] */
$throwsTags = $phpdoc->getTagsByName("throws");
if (count($throwsTags) > 0) {
foreach ($throwsTags as $throwsTag) {
$type = $throwsTag->getType();
$defRef = $this->getTypeDefinitionOrReference($type);
$routeDef["responses"][500] = ["schema" => $defRef, "description" => $throwsTag->getDescription()];
}
}
$routeDef["summary"] = $phpdoc->getShortDescription();
$description = $phpdoc->getLongDescription()->getContents();
if (strlen($description) > 0) {
$routeDef["description"] = $description;
}
$this->def['paths'][$path][$method] = $routeDef;
}