Skip to content

Commit

Permalink
Throw exception when validating file mime types and the HttpFoundatio…
Browse files Browse the repository at this point in the history
…n component is not installed
  • Loading branch information
pierredup committed May 19, 2020
1 parent b1c7383 commit cdc74bf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Validator/Constraints/FileValidator.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit cdc74bf

Please sign in to comment.