diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 52e937944188b..81bdca940c0b2 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\LogicException; use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Exception\UnexpectedValueException; @@ -171,6 +172,10 @@ public function validate($value, Constraint $constraint) if ($constraint->mimeTypes) { if (!$value instanceof FileObject) { + if (!class_exists(FileObject::class)) { + throw new LogicException('Validating mime types requires the "HttpFoundation" component. Install "symfony/http-foundation" to use it.'); + } + $value = new FileObject($value); }