AbstractComparison.php
1 year ago
AbstractComparisonValidator.php
1 year ago
All.php
1 year ago
AllValidator.php
4 years ago
AtLeastOneOf.php
1 year ago
AtLeastOneOfValidator.php
1 year ago
Bic.php
1 year ago
BicValidator.php
1 year ago
Blank.php
1 year ago
BlankValidator.php
4 years ago
Callback.php
1 year ago
CallbackValidator.php
4 years ago
CardScheme.php
1 year ago
CardSchemeValidator.php
1 year ago
Cascade.php
1 year ago
Choice.php
1 year ago
ChoiceValidator.php
1 year ago
Cidr.php
1 year ago
CidrValidator.php
4 years ago
Collection.php
1 year ago
CollectionValidator.php
4 years ago
Composite.php
1 year ago
Compound.php
4 years ago
CompoundValidator.php
4 years ago
Count.php
1 year ago
CountValidator.php
4 years ago
Country.php
1 year ago
CountryValidator.php
4 years ago
CssColor.php
1 year ago
CssColorValidator.php
1 year ago
Currency.php
1 year ago
CurrencyValidator.php
4 years ago
Date.php
1 year ago
DateTime.php
1 year ago
DateTimeValidator.php
2 years ago
DateValidator.php
1 year ago
DisableAutoMapping.php
1 year ago
DivisibleBy.php
4 years ago
DivisibleByValidator.php
4 years ago
Email.php
1 year ago
EmailValidator.php
1 year ago
EnableAutoMapping.php
1 year ago
EqualTo.php
4 years ago
EqualToValidator.php
4 years ago
Existence.php
4 years ago
Expression.php
1 year ago
ExpressionLanguageSyntax.php
1 year ago
ExpressionLanguageSyntaxValidator.php
1 year ago
ExpressionValidator.php
1 year ago
File.php
1 year ago
FileValidator.php
4 years ago
GreaterThan.php
4 years ago
GreaterThanOrEqual.php
4 years ago
GreaterThanOrEqualValidator.php
4 years ago
GreaterThanValidator.php
4 years ago
GroupSequence.php
4 years ago
GroupSequenceProvider.php
4 years ago
Hostname.php
1 year ago
HostnameValidator.php
4 years ago
Iban.php
1 year ago
IbanValidator.php
1 year ago
IdenticalTo.php
4 years ago
IdenticalToValidator.php
4 years ago
Image.php
1 year ago
ImageValidator.php
4 years ago
Ip.php
1 year ago
IpValidator.php
4 years ago
IsFalse.php
1 year ago
IsFalseValidator.php
4 years ago
IsNull.php
1 year ago
IsNullValidator.php
4 years ago
IsTrue.php
1 year ago
IsTrueValidator.php
4 years ago
Isbn.php
1 year ago
IsbnValidator.php
1 year ago
Isin.php
1 year ago
IsinValidator.php
4 years ago
Issn.php
1 year ago
IssnValidator.php
4 years ago
Json.php
1 year ago
JsonValidator.php
1 year ago
Language.php
1 year ago
LanguageValidator.php
4 years ago
Length.php
1 year ago
LengthValidator.php
4 years ago
LessThan.php
4 years ago
LessThanOrEqual.php
4 years ago
LessThanOrEqualValidator.php
4 years ago
LessThanValidator.php
4 years ago
Locale.php
1 year ago
LocaleValidator.php
4 years ago
Luhn.php
1 year ago
LuhnValidator.php
4 years ago
Negative.php
4 years ago
NegativeOrZero.php
4 years ago
NotBlank.php
1 year ago
NotBlankValidator.php
4 years ago
NotCompromisedPassword.php
1 year ago
NotCompromisedPasswordValidator.php
1 year ago
NotEqualTo.php
4 years ago
NotEqualToValidator.php
4 years ago
NotIdenticalTo.php
4 years ago
NotIdenticalToValidator.php
4 years ago
NotNull.php
1 year ago
NotNullValidator.php
4 years ago
NumberConstraintTrait.php
4 years ago
Optional.php
4 years ago
Positive.php
4 years ago
PositiveOrZero.php
4 years ago
Range.php
1 year ago
RangeValidator.php
1 year ago
Regex.php
1 year ago
RegexValidator.php
4 years ago
Required.php
4 years ago
Sequentially.php
1 year ago
SequentiallyValidator.php
4 years ago
Time.php
1 year ago
TimeValidator.php
1 year ago
Timezone.php
1 year ago
TimezoneValidator.php
1 year ago
Traverse.php
4 years ago
Type.php
1 year ago
TypeValidator.php
4 years ago
Ulid.php
1 year ago
UlidValidator.php
2 years ago
Unique.php
1 year ago
UniqueValidator.php
1 year ago
Url.php
1 year ago
UrlValidator.php
1 year ago
Uuid.php
1 year ago
UuidValidator.php
4 years ago
Valid.php
1 year ago
ValidValidator.php
4 years ago
ZeroComparisonConstraintTrait.php
1 year ago
index.php
3 years ago
File.php
97 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator\Constraints; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Constraint; |
| 5 | use MailPoetVendor\Symfony\Component\Validator\Exception\ConstraintDefinitionException; |
| 6 | #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] |
| 7 | class File extends Constraint |
| 8 | { |
| 9 | // Check the Image constraint for clashes if adding new constants here |
| 10 | public const NOT_FOUND_ERROR = 'd2a3fb6e-7ddc-4210-8fbf-2ab345ce1998'; |
| 11 | public const NOT_READABLE_ERROR = 'c20c92a4-5bfa-4202-9477-28e800e0f6ff'; |
| 12 | public const EMPTY_ERROR = '5d743385-9775-4aa5-8ff5-495fb1e60137'; |
| 13 | public const TOO_LARGE_ERROR = 'df8637af-d466-48c6-a59d-e7126250a654'; |
| 14 | public const INVALID_MIME_TYPE_ERROR = '744f00bc-4389-4c74-92de-9a43cde55534'; |
| 15 | protected static $errorNames = [self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR', self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR', self::EMPTY_ERROR => 'EMPTY_ERROR', self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR', self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR']; |
| 16 | public $binaryFormat; |
| 17 | public $mimeTypes = []; |
| 18 | public $notFoundMessage = 'The file could not be found.'; |
| 19 | public $notReadableMessage = 'The file is not readable.'; |
| 20 | public $maxSizeMessage = 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.'; |
| 21 | public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.'; |
| 22 | public $disallowEmptyMessage = 'An empty file is not allowed.'; |
| 23 | public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.'; |
| 24 | public $uploadFormSizeErrorMessage = 'The file is too large.'; |
| 25 | public $uploadPartialErrorMessage = 'The file was only partially uploaded.'; |
| 26 | public $uploadNoFileErrorMessage = 'No file was uploaded.'; |
| 27 | public $uploadNoTmpDirErrorMessage = 'No temporary folder was configured in php.ini.'; |
| 28 | public $uploadCantWriteErrorMessage = 'Cannot write temporary file to disk.'; |
| 29 | public $uploadExtensionErrorMessage = 'A PHP extension caused the upload to fail.'; |
| 30 | public $uploadErrorMessage = 'The file could not be uploaded.'; |
| 31 | protected $maxSize; |
| 32 | public function __construct(?array $options = null, $maxSize = null, ?bool $binaryFormat = null, $mimeTypes = null, ?string $notFoundMessage = null, ?string $notReadableMessage = null, ?string $maxSizeMessage = null, ?string $mimeTypesMessage = null, ?string $disallowEmptyMessage = null, ?string $uploadIniSizeErrorMessage = null, ?string $uploadFormSizeErrorMessage = null, ?string $uploadPartialErrorMessage = null, ?string $uploadNoFileErrorMessage = null, ?string $uploadNoTmpDirErrorMessage = null, ?string $uploadCantWriteErrorMessage = null, ?string $uploadExtensionErrorMessage = null, ?string $uploadErrorMessage = null, ?array $groups = null, $payload = null) |
| 33 | { |
| 34 | if (null !== $maxSize && !\is_int($maxSize) && !\is_string($maxSize)) { |
| 35 | throw new \TypeError(\sprintf('"%s": Expected argument $maxSize to be either null, an integer or a string, got "%s".', __METHOD__, \get_debug_type($maxSize))); |
| 36 | } |
| 37 | if (null !== $mimeTypes && !\is_array($mimeTypes) && !\is_string($mimeTypes)) { |
| 38 | throw new \TypeError(\sprintf('"%s": Expected argument $mimeTypes to be either null, an array or a string, got "%s".', __METHOD__, \get_debug_type($mimeTypes))); |
| 39 | } |
| 40 | parent::__construct($options, $groups, $payload); |
| 41 | $this->maxSize = $maxSize ?? $this->maxSize; |
| 42 | $this->binaryFormat = $binaryFormat ?? $this->binaryFormat; |
| 43 | $this->mimeTypes = $mimeTypes ?? $this->mimeTypes; |
| 44 | $this->notFoundMessage = $notFoundMessage ?? $this->notFoundMessage; |
| 45 | $this->notReadableMessage = $notReadableMessage ?? $this->notReadableMessage; |
| 46 | $this->maxSizeMessage = $maxSizeMessage ?? $this->maxSizeMessage; |
| 47 | $this->mimeTypesMessage = $mimeTypesMessage ?? $this->mimeTypesMessage; |
| 48 | $this->disallowEmptyMessage = $disallowEmptyMessage ?? $this->disallowEmptyMessage; |
| 49 | $this->uploadIniSizeErrorMessage = $uploadIniSizeErrorMessage ?? $this->uploadIniSizeErrorMessage; |
| 50 | $this->uploadFormSizeErrorMessage = $uploadFormSizeErrorMessage ?? $this->uploadFormSizeErrorMessage; |
| 51 | $this->uploadPartialErrorMessage = $uploadPartialErrorMessage ?? $this->uploadPartialErrorMessage; |
| 52 | $this->uploadNoFileErrorMessage = $uploadNoFileErrorMessage ?? $this->uploadNoFileErrorMessage; |
| 53 | $this->uploadNoTmpDirErrorMessage = $uploadNoTmpDirErrorMessage ?? $this->uploadNoTmpDirErrorMessage; |
| 54 | $this->uploadCantWriteErrorMessage = $uploadCantWriteErrorMessage ?? $this->uploadCantWriteErrorMessage; |
| 55 | $this->uploadExtensionErrorMessage = $uploadExtensionErrorMessage ?? $this->uploadExtensionErrorMessage; |
| 56 | $this->uploadErrorMessage = $uploadErrorMessage ?? $this->uploadErrorMessage; |
| 57 | if (null !== $this->maxSize) { |
| 58 | $this->normalizeBinaryFormat($this->maxSize); |
| 59 | } |
| 60 | } |
| 61 | public function __set(string $option, $value) |
| 62 | { |
| 63 | if ('maxSize' === $option) { |
| 64 | $this->normalizeBinaryFormat($value); |
| 65 | return; |
| 66 | } |
| 67 | parent::__set($option, $value); |
| 68 | } |
| 69 | public function __get(string $option) |
| 70 | { |
| 71 | if ('maxSize' === $option) { |
| 72 | return $this->maxSize; |
| 73 | } |
| 74 | return parent::__get($option); |
| 75 | } |
| 76 | public function __isset(string $option) |
| 77 | { |
| 78 | if ('maxSize' === $option) { |
| 79 | return \true; |
| 80 | } |
| 81 | return parent::__isset($option); |
| 82 | } |
| 83 | private function normalizeBinaryFormat($maxSize) |
| 84 | { |
| 85 | $factors = ['k' => 1000, 'ki' => 1 << 10, 'm' => 1000 * 1000, 'mi' => 1 << 20, 'g' => 1000 * 1000 * 1000, 'gi' => 1 << 30]; |
| 86 | if (\ctype_digit((string) $maxSize)) { |
| 87 | $this->maxSize = (int) $maxSize; |
| 88 | $this->binaryFormat = $this->binaryFormat ?? \false; |
| 89 | } elseif (\preg_match('/^(\\d++)(' . \implode('|', \array_keys($factors)) . ')$/i', $maxSize, $matches)) { |
| 90 | $this->maxSize = $matches[1] * $factors[$unit = \strtolower($matches[2])]; |
| 91 | $this->binaryFormat = $this->binaryFormat ?? 2 === \strlen($unit); |
| 92 | } else { |
| 93 | throw new ConstraintDefinitionException(\sprintf('"%s" is not a valid maximum size.', $maxSize)); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 |