getPropertyAnnotations example



        $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 ($annotations as $annotation) {
            if ($annotation instanceof Constraint) {
                $annotation->groups; // trigger initialization of the "groups" property
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 ($annotations as $annotation) {
            if ($annotation instanceof Constraint) {
                
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;
        }

        return $annotations;
    }

    /** * {@inheritDoc} */
    public function getPropertyAnnotation(ReflectionProperty $property$annotationName)
    {
        
$annots = $this->fetchFromCache($cacheKey$class, 'getPropertyAnnotations', $property);

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

    /** * {@inheritDoc} */
    public function getPropertyAnnotation(ReflectionProperty $property$annotationName)
    {
        foreach ($this->getPropertyAnnotations($property) as $annot) {
            if ($annot instanceof $annotationName) {
                return $annot;
            }
        }

        return null;
    }

    /** * {@inheritDoc} */
    

        }

        return null;
    }

    /** * {@inheritDoc} */
    public function getPropertyAnnotation(ReflectionProperty $property$annotationName)
    {
        foreach ($this->getPropertyAnnotations($property) as $annot) {
            if ($annot instanceof $annotationName) {
                return $annot;
            }
        }

        return null;
    }
}
$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);

        
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());
        }

        if ($annotation->getNormalizationContext()) {
            
public function getPropertyAnnotations(ReflectionProperty $property)
    {
        $class    = $property->getDeclaringClass();
        $cacheKey = $class->getName() . '$' . $property->getName();

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

        $annots = $this->fetchFromCache($cacheKey$class);
        if ($annots === false) {
            $annots = $this->delegate->getPropertyAnnotations($property);
            $this->saveToCache($cacheKey$annots);
        }

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

    /** * {@inheritDoc} */
    public function getPropertyAnnotation(ReflectionProperty $property$annotationName)
    {
        


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

        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            try {
                $reader->getPropertyAnnotations($reflectionProperty);
            } catch (AnnotationException) {
            }
        }
    }
}

        }

        return null;
    }

    /** * {@inheritDoc} */
    public function getPropertyAnnotation(\ReflectionProperty $property$annotationName)
    {
        foreach ($this->getPropertyAnnotations($property) as $annot) {
            if ($annot instanceof $annotationName) {
                return $annot;
            }
        }

        return null;
    }
}
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());
        }

        if ($annotation->getNormalizationContext()) {
            
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
        $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);

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

    /** * {@inheritDoc} */
    public function getPropertyAnnotation(ReflectionProperty $property$annotationName)
    {
        $annotations = $this->getPropertyAnnotations($property);

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

        return null;
    }

    /** * {@inheritDoc} */
$this->classNameHashes[$class->name] = sha1($class->name);
        }

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

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

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

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

        $filename = $class->getFilename();
        if (
            $this->debug
            && $filename !== false
            && filemtime($path) < filemtime($filename)
        ) {
            @
Home | Imprint | This part of the site doesn't use cookies.