Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit62ade6a

Browse files
committed
Use Mime component to determine mime type for file validator
1 parentfd584bb commit62ade6a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎src/Symfony/Component/Validator/Constraints/FileValidator.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
useSymfony\Component\HttpFoundation\File\FileasFileObject;
1515
useSymfony\Component\HttpFoundation\File\UploadedFile;
16+
useSymfony\Component\Mime\MimeTypes;
1617
useSymfony\Component\Validator\Constraint;
1718
useSymfony\Component\Validator\ConstraintValidator;
19+
useSymfony\Component\Validator\Exception\LogicException;
1820
useSymfony\Component\Validator\Exception\UnexpectedTypeException;
1921
useSymfony\Component\Validator\Exception\UnexpectedValueException;
2022

@@ -170,12 +172,12 @@ public function validate($value, Constraint $constraint)
170172
}
171173

172174
if ($constraint->mimeTypes) {
173-
if (!$valueinstanceof FileObject) {
174-
$value =newFileObject($value);
175+
if (!class_exists(MimeTypes::class)) {
176+
thrownewLogicException('You cannot validate the mime-type of files as the Mime component is not installed. Try running "composer require symfony/mime".');
175177
}
176178

177179
$mimeTypes = (array)$constraint->mimeTypes;
178-
$mime =$value->getMimeType();
180+
$mime =$valueinstanceof FileObject ?$value->getMimeType() : MimeTypes::getDefault()->guessMimeType($path);
179181

180182
foreach ($mimeTypesas$mimeType) {
181183
if ($mimeType ===$mime) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp