| 1 | <?php |
||
| 16 | class FileSizeValidator extends BaseObject implements ValidatorInterface |
||
| 17 | { |
||
| 18 | use ServerVariableTrait; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Error message |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | public $message = 'File size should be in range {minFileSize} and {maxFileSize} bytes'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Minimum file size |
||
| 29 | * |
||
| 30 | * @var int |
||
| 31 | */ |
||
| 32 | public $minFileSize = 0; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Maximum file size |
||
| 36 | * |
||
| 37 | * @var int |
||
| 38 | */ |
||
| 39 | public $maxFileSize = 10000000; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Validate file |
||
| 43 | * |
||
| 44 | * @param UploadedFile $file |
||
| 45 | * |
||
| 46 | * @return bool |
||
| 47 | */ |
||
| 48 | public function validate(UploadedFile &$file): bool |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Prepare and return error message |
||
| 72 | * |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | protected function getErrorMessage(): string |
||
| 79 | } |
||
| 80 |