diff --git a/.idea/files.iml b/.idea/files.iml
index 7233e26..a18a419 100644
--- a/.idea/files.iml
+++ b/.idea/files.iml
@@ -2,7 +2,6 @@
-
@@ -12,4 +11,4 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d7c5271..28a804d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,9 +3,4 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
index 64798a7..b5919b8 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -1,5 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -124,7 +136,10 @@
-
+
+
+
+
@@ -135,4 +150,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 95681f6..2df9f8a 100644
--- a/composer.json
+++ b/composer.json
@@ -8,7 +8,7 @@
}
],
"require": {
- "php": "^7.4 | ^8.0",
+ "php": "^8.0",
"league/mime-type-detection": "^1.7",
"gabrielelana/byte-units": "^0.5.0"
},
diff --git a/src/Validator/Constraint/File.php b/src/Validator/Constraint/File.php
index 5c10b56..e15ee71 100644
--- a/src/Validator/Constraint/File.php
+++ b/src/Validator/Constraint/File.php
@@ -4,6 +4,7 @@
namespace Arxy\FilesBundle\Validator\Constraint;
+use Attribute;
use Exception;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
@@ -16,29 +17,35 @@
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*/
+#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)]
class File extends Constraint
{
public ?int $maxSize = null;
- public string $maxSizeMessage = 'The file is too large ({{ size }}). Allowed maximum size is {{ limit }}.';
+
/** @var array */
public array $mimeTypes = [];
- public string $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
/**
- * @param array $options
- * @param array $groups
- * @param mixed $payload
+ * @param array|string $mimeTypes
+ * @param array|null $groups
*/
- public function __construct(array $options = null, array $groups = null, $payload = null)
- {
- if (isset($options['maxSize']) && is_string($options['maxSize'])) {
- $options['maxSize'] = $this->normalizeBinaryFormat($options['maxSize']);
+ public function __construct(
+ int|string|null $maxSize,
+ public string $maxSizeMessage = 'The file is too large ({{ size }}). Allowed maximum size is {{ limit }}.',
+ array|string $mimeTypes = [],
+ public string $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.',
+ array $groups = null,
+ ) {
+ if (is_string($maxSize)) {
+ $maxSize = $this->normalizeBinaryFormat($maxSize);
}
+ $this->maxSize = $maxSize;
- if (isset($options['mimeTypes']) && !is_array($options['mimeTypes'])) {
- $options['mimeTypes'] = [$options['mimeTypes']];
+ if (!is_array($mimeTypes)) {
+ $mimeTypes = [$mimeTypes];
}
- parent::__construct($options, $groups, $payload);
+ $this->mimeTypes = $mimeTypes;
+ parent::__construct(groups: $groups);
}
private function normalizeBinaryFormat(string $maxSize): int