Skip to content

Commit 1f4002b

Browse files
committed
Bump to symfony 8.0
1 parent 7d4836a commit 1f4002b

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

.idea/files.iml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99
],
1010
"require": {
11-
"php": "^7.4 | ^8.0",
11+
"php": "^8.0",
1212
"league/mime-type-detection": "^1.7",
1313
"gabrielelana/byte-units": "^0.5.0"
1414
},

src/Validator/Constraint/File.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Arxy\FilesBundle\Validator\Constraint;
66

7+
use Attribute;
78
use Exception;
89
use Symfony\Component\Validator\Constraint;
910
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
@@ -16,29 +17,35 @@
1617
* @Annotation
1718
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1819
*/
20+
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)]
1921
class File extends Constraint
2022
{
2123
public ?int $maxSize = null;
22-
public string $maxSizeMessage = 'The file is too large ({{ size }}). Allowed maximum size is {{ limit }}.';
24+
2325
/** @var array<int, string> */
2426
public array $mimeTypes = [];
25-
public string $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
2627

2728
/**
28-
* @param array<string, mixed> $options
29-
* @param array<int, string> $groups
30-
* @param mixed $payload
29+
* @param array<string>|string $mimeTypes
30+
* @param array<string>|null $groups
3131
*/
32-
public function __construct(array $options = null, array $groups = null, $payload = null)
33-
{
34-
if (isset($options['maxSize']) && is_string($options['maxSize'])) {
35-
$options['maxSize'] = $this->normalizeBinaryFormat($options['maxSize']);
32+
public function __construct(
33+
int|string|null $maxSize,
34+
public string $maxSizeMessage = 'The file is too large ({{ size }}). Allowed maximum size is {{ limit }}.',
35+
array|string $mimeTypes = [],
36+
public string $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.',
37+
array $groups = null,
38+
) {
39+
if (is_string($maxSize)) {
40+
$maxSize = $this->normalizeBinaryFormat($maxSize);
3641
}
42+
$this->maxSize = $maxSize;
3743

38-
if (isset($options['mimeTypes']) && !is_array($options['mimeTypes'])) {
39-
$options['mimeTypes'] = [$options['mimeTypes']];
44+
if (!is_array($mimeTypes)) {
45+
$mimeTypes = [$mimeTypes];
4046
}
41-
parent::__construct($options, $groups, $payload);
47+
$this->mimeTypes = $mimeTypes;
48+
parent::__construct(groups: $groups);
4249
}
4350

4451
private function normalizeBinaryFormat(string $maxSize): int

0 commit comments

Comments
 (0)