getMethodAnnotation example


    private function getMethodAnnotation(string $method, bool $attributes): Route
    {
        $class = $attributes ? FooAttributesController::class D FooController::class;
        $reflection = new \ReflectionMethod($class$method);

        if ($attributes) {
            $attributes = $reflection->getAttributes(Route::class);
            $route = $attributes[0]->newInstance();
        } else {
            $reader = new AnnotationReader();
            $route = $reader->getMethodAnnotation($reflection, Route::class);
        }

        if (!$route instanceof Route) {
            throw new \Exception('Can\'t parse annotation');
        }

        return $route;
    }

    /** * @dataProvider getValidParameters */
// do not run when this class is unit tested         if (!$this->testMode && $class === FeatureFlagExtensionTest::class) {
            // @codeCoverageIgnoreStart             return;
            // @codeCoverageIgnoreEnd         }

        $reflectedMethod = new \ReflectionMethod($class$method);

        /** @var DisabledFeatures[] $features */
        $features = array_filter([
            $this->annotationReader->getMethodAnnotation($reflectedMethod, DisabledFeatures::class) ?? [],
            $this->annotationReader->getClassAnnotation($reflectedMethod->getDeclaringClass(), DisabledFeatures::class) ?? [],
        ]);

        $this->savedFeatureConfig = null;

        if (!str_starts_with($class$this->namespacePrefix)) {
            return;
        }

        $this->savedFeatureConfig = Feature::getRegisteredFeatures();
        $this->savedServerVars = $_SERVER;

        
$annotations[get_class($annot)] = $annot;
        }

        return $annotations;
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotation(ReflectionMethod $method$annotationName)
    {
        return $this->delegate->getMethodAnnotation($method$annotationName);
    }

    /** * {@inheritDoc} */
    public function getPropertyAnnotations(ReflectionProperty $property)
    {
        $annotations = [];
        foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
            $annotations[get_class($annot)] = $annot;
        }

        
 catch (\Throwable) {
                // Symfony uses for their own controllers alias. We cannot find them easily                 continue;
            }

            // File is not in Platform Directory             if (!str_starts_with((string) $refClass->getFileName()(string) $platformDir)) {
                continue;
            }

            foreach ($refClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                $routeAnnotation = $annotationReader->getMethodAnnotation($method, Route::class);

                if ($routeAnnotation) {
                    $sinceAnnotation = $annotationReader->getMethodAnnotation($method, Since::class);

                    if ($sinceAnnotation === null) {
                        $missingSinceAnnotationOnRoutes[] = $routeName;
                    }
                }
            }
        }

        
Home | Imprint | This part of the site doesn't use cookies.