Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93b8e11

Browse files
committed
resolve @nicolas-grekas' comment
1 parent f4258f9 commit 93b8e11

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* Add the `When` constraint and validator
88
* Deprecate the "loose" e-mail validation mode, use "html5" instead
99
* Add the `negate` option to the `Expression` constraint, to inverse the logic of the violation's creation
10-
* Add the `extensions` option to the `File` constraint as an alternative to `mimeTypes` which checks the mime type of the file, its extension and the consistency between them
10+
* Add the `extensions` option to the `File` constraint as an alternative to `mimeTypes` which checks the mime type of the file, its extension, and the consistency between them
1111

1212
6.1
1313
---

src/Symfony/Component/Validator/Constraints/File.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
/**
1818
* @Annotation
19-
*
2019
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
2120
*
2221
* @property int $maxSize
@@ -50,10 +49,12 @@ class File extends Constraint
5049

5150
public $binaryFormat;
5251
public $mimeTypes = [];
52+
public array|string|null $extensions = [];
5353
public $notFoundMessage = 'The file could not be found.';
5454
public $notReadableMessage = 'The file is not readable.';
5555
public $maxSizeMessage = 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.';
5656
public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
57+
public string $extensionsMessage = 'The extension of the file is invalid ({{ extension }}). Allowed extensions are {{ extensions }}.';
5758
public $disallowEmptyMessage = 'An empty file is not allowed.';
5859

5960
public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.';
@@ -68,7 +69,7 @@ class File extends Constraint
6869
protected $maxSize;
6970

7071
/**
71-
* @param array<string, string[]>|string[]|string $extensions
72+
* @param array<string, string|string[]>|string[]|string $extensions
7273
*/
7374
public function __construct(
7475
array $options = null,
@@ -92,18 +93,20 @@ public function __construct(
9293
array $groups = null,
9394
mixed $payload = null,
9495

95-
public array|string|null $extensions = [],
96-
public string $extensionsMessage = 'The extension of the file is invalid ({{ extension }}). Allowed extensions are {{ extensions }}.',
96+
array|string $extensions = null,
97+
string $extensionsMessage = null,
9798
) {
9899
parent::__construct($options, $groups, $payload);
99100

100101
$this->maxSize = $maxSize ?? $this->maxSize;
101102
$this->binaryFormat = $binaryFormat ?? $this->binaryFormat;
102103
$this->mimeTypes = $mimeTypes ?? $this->mimeTypes;
104+
$this->extensions = $extensions ?? $this->extensions;
103105
$this->notFoundMessage = $notFoundMessage ?? $this->notFoundMessage;
104106
$this->notReadableMessage = $notReadableMessage ?? $this->notReadableMessage;
105107
$this->maxSizeMessage = $maxSizeMessage ?? $this->maxSizeMessage;
106108
$this->mimeTypesMessage = $mimeTypesMessage ?? $this->mimeTypesMessage;
109+
$this->extensionsMessage = $extensionsMessage ?? $this->extensionsMessage;
107110
$this->disallowEmptyMessage = $disallowEmptyMessage ?? $this->disallowEmptyMessage;
108111
$this->uploadIniSizeErrorMessage = $uploadIniSizeErrorMessage ?? $this->uploadIniSizeErrorMessage;
109112
$this->uploadFormSizeErrorMessage = $uploadFormSizeErrorMessage ?? $this->uploadFormSizeErrorMessage;

0 commit comments

Comments
 (0)