From cdc74bfa5d3e65e473861eefde020243a5f14cfb Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Tue, 19 May 2020 10:49:18 +0200 Subject: [PATCH] Throw exception when validating file mime types and the HttpFoundation component is not installed --- .../Component/Validator/Constraints/FileValidator.php | 5 +++++ 1 file changed, 5 insertions(+) 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); }