Checks whether a controller has an annotation on the class or method.

@param \ReflectionFunctionAbstract $controller
@param string                      $annotationClass

@return bool Whether the annotation is present.
423793
protected function hasControllerAnnotation(\ReflectionFunctionAbstract $controller, string $annotationClass) : bool
    {
        return $this->getControllerAnnotation($controller, $annotationClass) !== null;
    }
314230
@SuppressWarnings({ "rawtypes", "unchecked" })
    private static boolean isAnnotated(final Class clazz) {
        Plugin plugin = (Plugin) clazz.getAnnotation(Plugin.class);
        return plugin != null;
    }
476005
private function isExcludedClass($actionController)
    {
        foreach ($this->config->get('yaro.apidocs.exclude.classes', []) as $pattern) {
            if (str_is($pattern, $actionController)) {
                return true;
            }
        }
        
        return false;
    }
947644
public static boolean hasMethodWithAnnotation(Class<?> type,
                                                  Class<? extends Annotation> annotationType,
                                                  boolean checkMetaAnnotations) {
        try {
            do {
                Method[] methods = type.getDeclaredMethods();
                for (Method method : methods) {
                    if (hasAnnotation(method, annotationType, checkMetaAnnotations)) {
                        return true;
                    }
                }
                type = type.getSuperclass();
            } while (type != null);
        } catch (Throwable e) {
            // ignore a class loading issue
        }
        return false;
    }
340006
protected function _callAnnotation(Controller &$class, $annotation = [], $type = 'class', $annotationType = 'Before') {
        foreach ($annotation[$type] as $action => $annotationClasses) {
            foreach ($annotationClasses as $annotationClass) {
                if ($annotationClass['annotation'] == $annotationType) {
                    /** @var \Gcs\Framework\Core\Annotation\Annotations\Common\Before $instance */
                    $instance = $annotationClass['instance'];

                    $className = $instance->class;
                    $methodName = $instance->method;

                    if (method_exists($className, $methodName)) {
                        if ($className == get_class($class)) {
                            $class->$methodName();
                        }
                        else {
                            $reflectionMethod = new \ReflectionMethod($className, $methodName);
                            echo $reflectionMethod->invoke(new $className());
                        }
                    }
                    else {
                        throw new MissingMethodException('The method "' . $methodName . '" from the class "' . $className . '" does not exist');
                    }
                }
            }
        }
    }
1057745
private boolean containsAnnotation(List<AnnotationExpr> annos, String annotationName) {
        for (AnnotationExpr anno : annos) {
            if (anno.getName().getName().equals(annotationName)) {
                return true;
            }
        }
        return false;
    }
632826
public function containsMethodAnnotation($annotationName)
    {
        foreach ($this->getMethodAnnotations() as $annotations) {
            foreach ($annotations as $annotation) {
                if ($annotation instanceof $annotationName) {
                    return true;
                }
            }
        }

        return false;
    }
801950
private function isMethodReadable(\ReflectionMethod $method)
    {
        // if method starts with _ - skip
        if ('_' === substr($method->getName(), 0, 1)) {
            return false;
        }

        $hasNoRouteMethod = (bool) $this->readMethodAnnotation($method, 'NoRoute');
        $hasNoRouteClass = (bool) $this->readClassAnnotation($method->getDeclaringClass(), 'NoRoute');

        $hasNoRoute = $hasNoRouteMethod || $hasNoRouteClass;
        // since NoRoute extends Route we need to exclude all the method NoRoute annotations
        $hasRoute = (bool) $this->readMethodAnnotation($method, 'Route') && !$hasNoRouteMethod;

        // if method has NoRoute annotation and does not have Route annotation - skip
        if ($hasNoRoute && !$hasRoute) {
            return false;
        }

        return true;
    }
1371188
public function findController($controller)
    {
        $file = $this->basePath("app/Controller/$controller.php");
        if($this->findFile($file)) {
            return true;
        }
        else {
            throw new Exception($file." Controller file is missing.");
            exit;
        }
    }
615655
public function evaluateAnnotation(
        Request $request,
        Annotation $annotation,
        ReflectionMethod $method
    ) {
        /**
         * Annotation is only laoded if is typeof AnnotationFlush.
         */
        if ($annotation instanceof AnnotationFlush) {
            $managerName = $annotation->getManager()
                ?: $this->defaultManager;

            /**
             * Loading locally desired Doctrine manager.
             */
            $this->manager = $this
                ->doctrine
                ->getManager($managerName);

            /**
             * Set locally entities to flush. If null, flush all.
             */
            $this->entities = new ArrayCollection();
            $entity = $annotation->getEntity();
            $entities = is_array($entity)
                ? $entity
                : [$entity];

            /**
             * For every entity defined, we try to get it from Request Attributes.
             */
            foreach ($entities as $entityName) {
                if ($request->attributes->has($entityName)) {
                    $this->entities[] = $request->attributes->get($entityName);
                }
            }

            /**
             * If we have not found any entity to flush, or any has been defined.
             * In this case, flush all.
             */
            if ($this->entities->isEmpty()) {
                $this->entities = null;
            }

            /**
             * In this case, manager must be flushed after controller logic.
             */
            $this->mustFlush = true;
        }
    }
29716
static function getMethodAnnotation($method, $annotationName, $class = NULL)
	{
		$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);

		return static::instance()->getMethodAnnotation($method, $annotationName);
	}
1124240
public function resolveController($controller)
    {
        $callable = false;

        if (false !== strpos($controller, '::')) {
            list($controller_class, $method) = explode('::', $controller, 2);

            if (class_exists($controller_class)) {

                // Create controller class, and make sure method is callable
                $callable = array(new $controller_class(), $method);
                $callable = (is_callable($callable)) ? $callable : false;
            }
        }

        return($callable);
    }
164485
public function isClassAnnotatedWith($className, $annotationClassName)
    {
        if (!$this->initialized) {
            $this->initialize();
        }
        $className = $this->cleanClassName($className);

        $annotationClassName = $this->cleanClassName($annotationClassName);

        return (isset($this->annotatedClasses[$annotationClassName][$className]));
    }
948815
protected function extractAnnotation(KernelEvent $event, $annotationClassName)
    {
        $controller = $this->resolver->getController($event->getRequest());
        $reflectionClass = new \ReflectionClass($controller[0]);
        $annot = $this->annotationReader->getMethodAnnotation($reflectionClass->getMethod(
            $controller[1]),
            $annotationClassName
        );

        if(!$annot) {
            $annot = $this->annotationReader->getClassAnnotation($reflectionClass, $annotationClassName);
        }

        return $annot;
    }
300254
private function isControllerClassNameValid($controllerClassName)
    {
        $returnValue = true;

        if (!class_exists($controllerClassName)) {
            common_Logger::w($controllerClassName.' not found');
            $returnValue = false;
        } elseif (!is_subclass_of($controllerClassName, 'Module') && !is_subclass_of($controllerClassName, Controller::class)) {
            common_Logger::w($controllerClassName.' is not a valid Controller.');
            $returnValue = false;
        } else {
            // abstract so just move along
            $reflection = new \ReflectionClass($controllerClassName);
            if ($reflection->isAbstract()) {
                common_Logger::i($controllerClassName.' is abstract');
                $returnValue = false;
            }
        }

        return $returnValue;
    }
970637
public static function getAnnotationParams($controller, $action)
    {
        $result = [];

        $reflection = new \ReflectionClass($controller);
        $res = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
        foreach ($res as $method) {
            if ($method->name == $action) {
                $annotation = $method->getDocComment();
                if (strpos($annotation, '@doc') !== false) {
                    //$result[$version][$model]['all'] = $annotation;
                    //描述
                    preg_match('/@desc([^\n]+)/', $annotation, $desc);
                    $result['desc'] = isset($desc[1]) ? trim($desc[1]) : '';
                    //参数
                    preg_match_all('/@param([^\n]+)/', $annotation, $params);
                    foreach ($params[1] as $key => $val) {
                        $tmp = explode(' ', preg_replace('/\s(\s+)/', ' ', trim($val)));
                        isset($tmp[3]) || $tmp[3] = 'N';
                        substr($tmp[1], 0, 1) == '$' && $tmp[1] = substr($tmp[1], 1);
                        $result['params'][] = $tmp;
                    }

                    //请求示例
                    preg_match('/@req(.+?)(\*\s*?@|\*\/)/s', $annotation, $reqEg);
                    $result['req'] = isset($reqEg[1]) ? self::formatCode($reqEg[1]) : '';

                    //请求成功示例
                    preg_match('/@success(.+?)(\*\s*?@|\*\/)/s', $annotation, $success);
                    $result['success'] = isset($success[1]) ? self::formatCode($success[1]) : '';

                    //请求失败示例
                    preg_match('/@error(.+?)(\*\s*?@|\*\/)/s', $annotation, $error);
                    $result['error'] = isset($error[1]) ? self::formatCode($error[1]) : '';
                }
            }
        }
        return $result;
    }
13013
private function invalidScalarParameterException(\ReflectionFunctionAbstract $controller, RequestParam $annotation, string $type) : HttpBadRequestException
    {
        return new HttpBadRequestException(sprintf(
            '%s() received an invalid %s value for %s parameter "%s" (bound to $%s).',
            $this->reflectionTools->getFunctionName($controller),
            $type,
            $annotation->getParameterType(),
            $annotation->getName(),
            $annotation->getBindTo()
        ));
    }