@param ReflectionClass $controller
@param ReflectionMethod $method

@return string
2720
protected function getRouteGroup(ReflectionClass $controller, ReflectionMethod $method)
    {
        // @group tag on the method overrides that on the controller
        $docBlockComment = $method->getDocComment();
        if ($docBlockComment) {
            $phpdoc = new DocBlock($docBlockComment);
            foreach ($phpdoc->getTags() as $tag) {
                if ($tag->getName() === 'group') {
                    return $tag->getContent();
                }
            }
        }

        $docBlockComment = $controller->getDocComment();
        if ($docBlockComment) {
            $phpdoc = new DocBlock($docBlockComment);
            foreach ($phpdoc->getTags() as $tag) {
                if ($tag->getName() === 'group') {
                    return $tag->getContent();
                }
            }
        }

        return config('apidoc.default_group', 'general');
    }
165951
private function readMethodAnnotations(\ReflectionMethod $reflectionMethod, $annotationName)
    {
        $annotations = [];
        $annotationClass = "FOS\\RestBundle\\Controller\\Annotations\\$annotationName";

        if ($annotations_new = $this->annotationReader->getMethodAnnotations($reflectionMethod)) {
            foreach ($annotations_new as $annotation) {
                if ($annotation instanceof $annotationClass) {
                    $annotations[] = $annotation;
                }
            }
        }

        return $annotations;
    }
684070
private function getRoutePattern($reflectionMethod)
    {
        $pattern = $reflectionMethod->getName();
        $params = $reflectionMethod->getParameters();

        foreach ($params as $param) {
            if ($param->getClass()) {
                $className = $param->getClass()->getShortName();

                if ($className != 'Request' && $className != 'Application') {
                    $pattern .= '/{'.$param->getName().'}';
                }
            } else {
                $pattern .= '/{'.$param->getName().'}';
            }
        }

        return $pattern;
    }
1179311
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
    {
        $routeName = parent::getDefaultRouteName($class, $method);

        return preg_replace(array(
            '/(module_|controller_?)/',
            '/__/'
        ), array(
            '_',
            '_'
        ), $routeName);
    }
549219
private function detectClassAndMethod(string $controller): ?array
    {
        if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) {
            $class = $matches[1];
            $method = $matches[2];
        } elseif (class_exists($controller)) {
            $class = $controller;
            $method = '__invoke';
        } else {
            if (preg_match('#(.+):([\w]+)#', $controller, $matches)) {
                $controller = $matches[1];
                $method = $matches[2];
            }

            if ($this->container->has($controller)) {
                $class = get_class($this->container->get($controller));

                if (!isset($method) && method_exists($class, '__invoke')) {
                    $method = '__invoke';
                }
            }
        }

        if (!isset($class) || !isset($method)) {
            return null;
        }

        return [$class, $method];
    }
879864
private static function getMethodParamTpls(\ReflectionMethod $method)
    {
        $result = [
            'args'      => [],
            'define'    => [],
            'call'      => [],
            'set_args'  => '',
        ];
        foreach($method->getParameters() as $i => $param)
        {
            // 数组参数，支持可变传参
            if(!$param->isVariadic())
            {
                $result['args'][] = static::getMethodParamArgsTpl($param);
            }
            // 方法参数定义
            $result['define'][] = static::getMethodParamDefineTpl($param);
            // 调用传参
            $result['call'][] = static::getMethodParamCallTpl($param);
            // 引用传参
            if($param->isPassedByReference())
            {
                $result['set_args'] .= '$__args__[' . $i . '] = &$' . $param->name . ';';
            }
        }
        foreach($result as $key => &$item)
        {
            if(is_array($item))
            {
                $item = implode(',', $item);
            }
        }
        // 调用如果参数为空处理
        if('' === $result['call'])
        {
            $result['call'] = '...func_get_args()';
        }
        return $result;
    }
971741
private function getMethod(\ReflectionMethod $method)
    {
        $methodStmt = $this->factory->method($method->name);
        $params = $method->getParameters();
        foreach ($params as $param) {
            $methodStmt = $this->getMethodStatement($param, $methodStmt);
        }
        $returnType = $method->getReturnType();
        if ($returnType instanceof \ReflectionType) {
            $this->setReturnType($returnType, $methodStmt);
        }
        $methodInsideStatements = $this->getMethodInsideStatement($method);
        $methodStmt->addStmts($methodInsideStatements);

        return $this->addMethodDocComment($methodStmt, $method);
    }
980186
protected function getControllerMiddlewareFromInstance($controller, $method)
    {
        $middlewares = $this->router->getMiddleware();

        //
        $results = array();

        foreach ($controller->getMiddleware() as $middleware => $options) {
            if (ControllerDispatcher::methodExcludedByOptions($method, $options)) {
                continue;
            }

            list($name, $parameters) = array_pad(explode(':', $middleware, 2), 2, null);

            $middleware = Arr::get($middlewares, $name, $name);

            $results[] = (! $middleware instanceof Closure) ? $middleware : $name;
        }

        return $results;
    }
1059670
public static function reflectClassMethod($class, $method, $output = true)
    {
        $data = '';

        $reflectionMethod = new \ReflectionMethod($class, $method);

        $comment = $reflectionMethod->getDocComment();
        if (!empty($comment)) {
            $data .= "\n";
            $data .= "\t";
            $data .= $comment;
        }

        $data .= "\n";
        $data .= "\t";
        $data .= ($reflectionMethod->isPublic() ? 'public ' : '');
        $data .= ($reflectionMethod->isPrivate() ? 'private ' : '');
        $data .= ($reflectionMethod->isProtected() ? 'protected ' : '');
        $data .= ($reflectionMethod->isStatic() ? 'static ' : '');
        $data .= 'function ' . $reflectionMethod->name . '(';
        if ($reflectionMethod->getNumberOfParameters()) {
            foreach ($reflectionMethod->getParameters() as $reflectionMethodParameterIndex => $reflectionMethodParameter) {
                $data .= ($reflectionMethodParameterIndex > 0 ? ', ' : '');
                $data .= '$' . $reflectionMethodParameter->name;
                if ($reflectionMethodParameter->isDefaultValueAvailable()) {
                    $defaultValue = self::getDebugInformation($reflectionMethodParameter->getDefaultValue());
                    $defaultValue = str_replace(["\n", "\t"], '', $defaultValue);
                    $data         .= ' = ' . $defaultValue;
                }
            }
        }
        $data .= ') {}';

        if ($output) {
            self::output($data);
        }

        return $data;
    }
390014
protected function tryRunMethod($controller, $method)
    {
        if ($method === "options") {
            $classMethods = get_class_methods($controller);
            $classMethodsResult = ["options"];
            foreach ($classMethods as $val) {
                if (!in_array($val, array("__construct", "__distruct"))) {
                    $classMethodsResult[] = $val;
                }
            }
            $acceptMethods = strtoupper(implode(",", $classMethodsResult));
            $response = new Response("", Response::HTTP_OK);
            $response->headers->set("Allow", $acceptMethods);
            $response->headers->set("access-control-allow-methods", $acceptMethods);
            $response->send();
        } else {
            try {
                return $controller->$method();
            } catch (\RuntimeException $e) {
                throw new \Exception($e);
            }
        }
    }
915937
public static function invalidControllerClassMethod(\ReflectionException $e, string $class, string $method) : RoutingException
    {
        return new self(sprintf(
            'Cannot find a controller method called %s::%s().',
            $class,
            $method
        ), 0, $e);
    }
99609
private function getMethodArguments(\ReflectionMethod $method)
    {
        // ignore all query params
        $params = $this->paramReader->getParamsFromMethod($method);

        // check if a parameter is coming from the request body
        $ignoreParameters = [];
        if (class_exists(ParamConverter::class)) {
            $ignoreParameters = array_map(function ($annotation) {
                return
                    $annotation instanceof ParamConverter &&
                    'fos_rest.request_body' === $annotation->getConverter()
                        ? $annotation->getName() : null;
            }, $this->annotationReader->getMethodAnnotations($method));
        }

        // ignore several type hinted arguments
        $ignoreClasses = [
            Request::class,
            ParamFetcherInterface::class,
            ConstraintViolationListInterface::class,
            ParamConverter::class,
            MessageInterface::class,
        ];

        $arguments = [];
        foreach ($method->getParameters() as $argument) {
            if (isset($params[$argument->getName()])) {
                continue;
            }

            $argumentClass = $argument->getClass();
            if ($argumentClass) {
                $className = $argumentClass->getName();
                foreach ($ignoreClasses as $class) {
                    if ($className === $class || is_subclass_of($className, $class)) {
                        continue 2;
                    }
                }
            }

            if (in_array($argument->getName(), $ignoreParameters, true)) {
                continue;
            }

            $arguments[] = $argument;
        }

        return $arguments;
    }
259571
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
    {
        $name = strtolower(str_replace('\\', '_', $class->name).'_'.$method->name);
        if ($this->defaultRouteIndex > 0) {
            $name .= '_'.$this->defaultRouteIndex;
        }
        ++$this->defaultRouteIndex;

        return $name;
    }
1361878
private static function getMethodsTemplate(array $reflectionMethods, string $handlerPropertyName): string
    {
        $template = '';
        foreach ($reflectionMethods as $reflectionMethod) {
            $methodName = $reflectionMethod->getName();

            // not to override method
            if ($reflectionMethod->isConstructor() || $reflectionMethod->isStatic()) {
                continue;
            }
            
            // define override methodBody
            $methodBody = "{
                return \$this->{$handlerPropertyName}->invoke('{$methodName}', func_get_args());
            }
            ";
            
            // the template of parameter
            $template .= " public function $methodName (";
            $template .= self::getParameterTemplate($reflectionMethod);
            $template .= ' ) ';

            // the template of return type
            $reflectionMethodReturn = $reflectionMethod->getReturnType();
            if ($reflectionMethodReturn !== null) {
                $returnType = $reflectionMethodReturn->__toString();
                $returnType = $returnType === 'self' ? $reflectionMethod->getDeclaringClass()->getName() : $returnType;
                $template .= " : $returnType";
                // if returnType is void
                if ($returnType === 'void') {
                    $methodBody = str_replace('return ', '', $methodBody);
                }
            }

            // append methodBody
            $template .= $methodBody;
        }

        return $template;
    }
582491
private function getClassAndMethod(string $controller)
    {
        if (!isset($this->controllers[$controller])) {
            $this->controllers[$controller] = $this->detectClassAndMethod($controller);
        }

        return $this->controllers[$controller];
    }
749179
protected function getMethod(RouteMatchInterface $routeMatch): ReflectionMethod
    {
        $action = $this->getAction($routeMatch);

        return new ReflectionMethod($this, $action . $this->getPostfix());
    }
601045
protected function getMethodCode(\ReflectionMethod $reflectionMethod)
    {
        $file = file($reflectionMethod->getFileName());

        $methodCodeLines = array();
        foreach (range($reflectionMethod->getStartLine(), $reflectionMethod->getEndLine() - 1) as $line) {
            $methodCodeLines[] = $file[$line];
        }

        return array_values($methodCodeLines);
    }