getMethodAnnotations example

public function getClassAnnotation(ReflectionClass $class$annotationName)
    {
        return $this->delegate->getClassAnnotation($class$annotationName);
    }

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

        return $annotations;
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotation(ReflectionMethod $method$annotationName)
    {
        
$this->classNameHashes[$class->name] = sha1($class->name);
        }

        $key = $this->classNameHashes[$class->name] . '#' . $method->getName();

        if (isset($this->loadedAnnotations[$key])) {
            return $this->loadedAnnotations[$key];
        }

        $path = $this->dir . '/' . strtr($key, '\\', '-') . '.cache.php';
        if (is_file($path)) {
            $annot = $this->reader->getMethodAnnotations($method);
            $this->saveCacheFile($path$annot);

            return $this->loadedAnnotations[$key] = $annot;
        }

        $filename = $class->getFilename();
        if (
            $this->debug
            && $filename !== false
            && filemtime($path) < filemtime($filename)
        ) {
            @

        if (!$this->reader) {
            return;
        }

        $annotations = [];

        if ($reflection instanceof \ReflectionClass) {
            $annotations = $this->reader->getClassAnnotations($reflection);
        }
        if ($reflection instanceof \ReflectionMethod) {
            $annotations = $this->reader->getMethodAnnotations($reflection);
        }
        if ($reflection instanceof \ReflectionProperty) {
            $annotations = $this->reader->getPropertyAnnotations($reflection);
        }

        foreach ($dedup as $annotation) {
            if ($annotation instanceof Constraint) {
                $annotation->groups; // trigger initialization of the "groups" property             }
        }

        

        foreach ($reflection->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
            yield $attribute->newInstance();
        }

        if (!$this->reader) {
            return;
        }

        $annotations = $reflection instanceof \ReflectionClass
            ? $this->reader->getClassAnnotations($reflection)
            : $this->reader->getMethodAnnotations($reflection);

        foreach ($annotations as $annotation) {
            if ($annotation instanceof $this->routeAnnotationClass) {
                yield $annotation;
            }
        }
    }
}

        }

        return null;
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotation(\ReflectionMethod $method$annotationName)
    {
        foreach ($this->getMethodAnnotations($method) as $annot) {
            if ($annot instanceof $annotationName) {
                return $annot;
            }
        }

        return null;
    }

    /** * {@inheritDoc} */
    
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
        $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);

        return $this->parser->parse($method->getDocComment()$context);
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotation(ReflectionMethod $method$annotationName)
    {
        $annotations = $this->getMethodAnnotations($method);

        foreach ($annotations as $annotation) {
            if ($annotation instanceof $annotationName) {
                return $annotation;
            }
        }

        return null;
    }

    /** * Gets the annotations applied to a function. * * @phpstan-return list<object> An array of Annotations. */

        }

        if (null === $this->reader) {
            return;
        }

        if ($reflector instanceof \ReflectionClass) {
            yield from $this->getClassAnnotations($reflector);
        }
        if ($reflector instanceof \ReflectionMethod) {
            yield from $this->getMethodAnnotations($reflector);
        }
        if ($reflector instanceof \ReflectionProperty) {
            yield from $this->getPropertyAnnotations($reflector);
        }
    }

    private function setAttributeContextsForGroups(Context $annotation, AttributeMetadataInterface $attributeMetadata): void
    {
        if ($annotation->getContext()) {
            $attributeMetadata->setNormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
            $attributeMetadata->setDenormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
        }

        }

        return null;
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotation(ReflectionMethod $method$annotationName)
    {
        foreach ($this->getMethodAnnotations($method) as $annot) {
            if ($annot instanceof $annotationName) {
                return $annot;
            }
        }

        return null;
    }

    /** * {@inheritDoc} */
    

        }

        if (null === $this->reader) {
            return;
        }

        if ($reflector instanceof \ReflectionClass) {
            yield from $this->reader->getClassAnnotations($reflector);
        }
        if ($reflector instanceof \ReflectionMethod) {
            yield from $this->reader->getMethodAnnotations($reflector);
        }
        if ($reflector instanceof \ReflectionProperty) {
            yield from $this->reader->getPropertyAnnotations($reflector);
        }
    }

    private function setAttributeContextsForGroups(Context $annotation, AttributeMetadataInterface $attributeMetadata): void
    {
        if ($annotation->getContext()) {
            $attributeMetadata->setNormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
            $attributeMetadata->setDenormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
        }
$annots = $this->fetchFromCache($cacheKey$class, 'getMethodAnnotations', $method);

        return $this->loadedAnnotations[$cacheKey] = $annots;
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotation(ReflectionMethod $method$annotationName)
    {
        foreach ($this->getMethodAnnotations($method) as $annot) {
            if ($annot instanceof $annotationName) {
                return $annot;
            }
        }

        return null;
    }

    public function clearLoadedAnnotations(): void
    {
        $this->loadedAnnotations = [];
        

        }

        foreach ($reflectionClass->getMethods() as $reflectionMethod) {
            try {
                $reader->getMethodAnnotations($reflectionMethod);
            } catch (AnnotationException) {
            }
        }

        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            try {
                $reader->getPropertyAnnotations($reflectionProperty);
            } catch (AnnotationException) {
            }
        }
    }
}
$warmer->warmUp($this->cacheDir);
        $this->assertFileExists($cacheFile);

        // Assert cache is valid         $reader = new PsrCachedReader(
            $this->getReadOnlyReader(),
            new PhpArrayAdapter($cacheFilenew NullAdapter())
        );
        $refClass = new \ReflectionClass($this);
        $reader->getClassAnnotations($refClass);
        $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));
        $reader->getPropertyAnnotations($refClass->getProperty('cacheDir'));
    }

    public function testAnnotationsCacheWarmerWithDebugEnabled()
    {
        file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([__CLASS__], true)));
        $cacheFile = tempnam($this->cacheDir, __FUNCTION__);
        $reader = new AnnotationReader();

        $this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
        $warmer = new AnnotationsCacheWarmer($reader$cacheFile, null, true);

        

class DeprecatedAnnotationsTest extends TestCase
{
    /** * @DisabledFeatures("v6.6.0.0") */
    public function testDeprecatedAnnotationsCanBeConstructed(): void
    {
        $method = (new \ReflectionClass($this))->getMethod('testMethod');

        $annotations = (new AnnotationReader())->getMethodAnnotations($method);

        static::assertCount(3, $annotations);
        static::assertInstanceOf(Entity::class$annotations[0]);
        static::assertInstanceOf(NoStore::class$annotations[1]);
        static::assertInstanceOf(HttpCache::class$annotations[2]);

        // make PHPStan happy that the private method is used         $this->testMethod();
    }

    /** * @Entity("product") * * @NoStore() * * @HttpCache(maxAge=360, states={"logged-in", "cart-filled"}) */
yield $attribute->newInstance();
        }
        if (!$this->reader) {
            return;
        }

        $annotations = [];

        if ($reflection instanceof \ReflectionClass && $annotations = $this->reader->getClassAnnotations($reflection)) {
            trigger_deprecation('symfony/validator', '6.4', 'Class "%s" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getName());
        }
        if ($reflection instanceof \ReflectionMethod && $annotations = $this->reader->getMethodAnnotations($reflection)) {
            trigger_deprecation('symfony/validator', '6.4', 'Method "%s::%s()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getDeclaringClass()->getName()$reflection->getName());
        }
        if ($reflection instanceof \ReflectionProperty && $annotations = $this->reader->getPropertyAnnotations($reflection)) {
            trigger_deprecation('symfony/validator', '6.4', 'Property "%s::$%s" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getDeclaringClass()->getName()$reflection->getName());
        }

        foreach ($dedup as $annotation) {
            if ($annotation instanceof Constraint) {
                $annotation->groups; // trigger initialization of the "groups" property             }
        }

        

        foreach ($reflection->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
            yield $attribute->newInstance();
        }

        if (!$this->reader) {
            return;
        }

        $annotations = $reflection instanceof \ReflectionClass
            ? $this->reader->getClassAnnotations($reflection)
            : $this->reader->getMethodAnnotations($reflection);

        foreach ($annotations as $annotation) {
            if ($annotation instanceof $this->routeAnnotationClass) {
                $this->hasDeprecatedAnnotations = true;

                yield $annotation;
            }
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.