当前位置: 首页>>代码示例>>PHP>>正文


PHP Reflector::getReflectionFunctionForCallable方法代码示例

本文整理汇总了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;
 }
开发者ID:digitalcreations,项目名称:router-swagger,代码行数:80,代码来源:SwaggerDefinitionBuilder.php


注:本文中的Reflector::getReflectionFunctionForCallable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。