Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Validator\Mapping\Loader;
  11. use Doctrine\Common\Annotations\Reader;
  12. use Symfony\Component\Validator\Constraint;
  13. use Symfony\Component\Validator\Constraints\Callback;
  14. use Symfony\Component\Validator\Constraints\GroupSequence;
  15. use Symfony\Component\Validator\Constraints\GroupSequenceProvider;
  16. use Symfony\Component\Validator\Exception\MappingException;
  17. use Symfony\Component\Validator\Mapping\ClassMetadata;
  18. /**
  19.  * Loads validation metadata using a Doctrine annotation {@link Reader} or using PHP 8 attributes.
  20.  *
  21.  * @author Bernhard Schussek <bschussek@gmail.com>
  22.  * @author Alexander M. Turek <me@derrabus.de>
  23.  */
  24. class AnnotationLoader implements LoaderInterface
  25. {
  26.     protected $reader;
  27.     public function __construct(Reader $reader null)
  28.     {
  29.         $this->reader $reader;
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function loadClassMetadata(ClassMetadata $metadata)
  35.     {
  36.         $reflClass $metadata->getReflectionClass();
  37.         $className $reflClass->name;
  38.         $success false;
  39.         foreach ($this->getAnnotations($reflClass) as $constraint) {
  40.             if ($constraint instanceof GroupSequence) {
  41.                 $metadata->setGroupSequence($constraint->groups);
  42.             } elseif ($constraint instanceof GroupSequenceProvider) {
  43.                 $metadata->setGroupSequenceProvider(true);
  44.             } elseif ($constraint instanceof Constraint) {
  45.                 $metadata->addConstraint($constraint);
  46.             }
  47.             $success true;
  48.         }
  49.         foreach ($reflClass->getProperties() as $property) {
  50.             if ($property->getDeclaringClass()->name === $className) {
  51.                 foreach ($this->getAnnotations($property) as $constraint) {
  52.                     if ($constraint instanceof Constraint) {
  53.                         $metadata->addPropertyConstraint($property->name$constraint);
  54.                     }
  55.                     $success true;
  56.                 }
  57.             }
  58.         }
  59.         foreach ($reflClass->getMethods() as $method) {
  60.             if ($method->getDeclaringClass()->name === $className) {
  61.                 foreach ($this->getAnnotations($method) as $constraint) {
  62.                     if ($constraint instanceof Callback) {
  63.                         $constraint->callback $method->getName();
  64.                         $metadata->addConstraint($constraint);
  65.                     } elseif ($constraint instanceof Constraint) {
  66.                         if (preg_match('/^(get|is|has)(.+)$/i'$method->name$matches)) {
  67.                             $metadata->addGetterMethodConstraint(lcfirst($matches[2]), $matches[0], $constraint);
  68.                         } else {
  69.                             throw new MappingException(sprintf('The constraint on "%s::%s()" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".'$className$method->name));
  70.                         }
  71.                     }
  72.                     $success true;
  73.                 }
  74.             }
  75.         }
  76.         return $success;
  77.     }
  78.     /**
  79.      * @param \ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflection
  80.      */
  81.     private function getAnnotations(object $reflection): iterable
  82.     {
  83.         $dedup = [];
  84.         if (\PHP_VERSION_ID >= 80000) {
  85.             foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) {
  86.                 $dedup[] = $attribute->newInstance();
  87.                 yield $attribute->newInstance();
  88.             }
  89.             foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) {
  90.                 $dedup[] = $attribute->newInstance();
  91.                 yield $attribute->newInstance();
  92.             }
  93.             foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
  94.                 $dedup[] = $attribute->newInstance();
  95.                 yield $attribute->newInstance();
  96.             }
  97.         }
  98.         if (!$this->reader) {
  99.             return;
  100.         }
  101.         $annotations = [];
  102.         if ($reflection instanceof \ReflectionClass) {
  103.             $annotations $this->reader->getClassAnnotations($reflection);
  104.         }
  105.         if ($reflection instanceof \ReflectionMethod) {
  106.             $annotations $this->reader->getMethodAnnotations($reflection);
  107.         }
  108.         if ($reflection instanceof \ReflectionProperty) {
  109.             $annotations $this->reader->getPropertyAnnotations($reflection);
  110.         }
  111.         foreach ($dedup as $annotation) {
  112.             if ($annotation instanceof Constraint) {
  113.                 $annotation->groups// trigger initialization of the "groups" property
  114.             }
  115.         }
  116.         foreach ($annotations as $annotation) {
  117.             if ($annotation instanceof Constraint) {
  118.                 $annotation->groups// trigger initialization of the "groups" property
  119.             }
  120.             if (!\in_array($annotation$dedupfalse)) {
  121.                 yield $annotation;
  122.             }
  123.         }
  124.     }
  125. }