Merge pull request #1833 from NicolasCharpentier/NicolasCharpentier-patch-symfony-validator-optional-dependency

Add a check for Constraint class existing before using it
This commit is contained in:
Guilhem Niot 2021-06-14 13:23:15 +02:00 committed by GitHub
commit b2c5b619a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,7 +166,7 @@ class SymfonyConstraintAnnotationReader
*/ */
private function getAnnotations($reflection): \Traversable private function getAnnotations($reflection): \Traversable
{ {
if (\PHP_VERSION_ID >= 80000) { if (\PHP_VERSION_ID >= 80000 && class_exists(Constraint::class)) {
foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
yield $attribute->newInstance(); yield $attribute->newInstance();
} }