File
class File implements Rule, DataAwareRule, ValidatorAwareRule
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected array | $allowedMimetypes | The MIME types that the given file should match. This array may also contain file extensions. |
|
| protected array | $allowedExtensions | The extensions that the given file should match. |
|
| protected int|null | $minimumFileSize | The minimum size in kilobytes that the file can be. |
|
| protected int|null | $maximumFileSize | The maximum size in kilobytes that the file can be. |
|
| protected string|null | $encoding | The required file encoding. |
|
| protected array | $customRules | An array of custom rules that will be merged into the validation rules. |
|
| protected array | $messages | The error message after validation, if any. |
|
| protected array | $data | The data under validation. |
|
| protected Validator|null | $validator | The validator performing the validation. |
|
| static null|array|callable|string | $defaultCallback | The callback that will generate the "default" version of the file rule. |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Set the default callback to be used for determining the file default rules.
Limit the uploaded file to the given MIME types or file extensions.
Limit the uploaded file to the given file extensions.
Indicate that the uploaded file should be exactly a certain size in kilobytes.
Indicate that the uploaded file should be between a minimum and maximum size in kilobytes.
Indicate that the uploaded file should be no less than the given number of kilobytes.
Indicate that the uploaded file should be no more than the given number of kilobytes.
Convert a potentially human-friendly file size to kilobytes.
Specify additional validation rules that should be merged with the default rules during validation.
Determine if the validation rule passes.
Build the array of underlying validation rules based on the current state.
Separate the given MIME types from extensions and return an array of correct rules to validate against.
Adds the given failures, and return false.
Get the validation error message.
Set the current data under validation.
Flush all static state.
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
ClonesCustomRules at line 15
void
__clone()
Clone the nested executable rule objects.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 93
static File|null
defaults(mixed $callback = null)
Set the default callback to be used for determining the file default rules.
If no arguments are passed, the default file rule configuration will be returned.
A given callback persists in a static property for the worker lifetime and is used by every File::default() call across all coroutines.
at line 112
static File
default()
Get the default configuration of the file rule.
at line 132
static ImageFile
image(bool $allowSvg = false)
Limit the uploaded file to only image types.
at line 142
static File
types(array|string $mimetypes)
Limit the uploaded file to the given MIME types or file extensions.
at line 152
File
extensions(array|string $extensions)
Limit the uploaded file to the given file extensions.
at line 164
File
size(int|string $size)
Indicate that the uploaded file should be exactly a certain size in kilobytes.
at line 177
File
between(int|string $minSize, int|string $maxSize)
Indicate that the uploaded file should be between a minimum and maximum size in kilobytes.
at line 190
File
min(int|string $size)
Indicate that the uploaded file should be no less than the given number of kilobytes.
at line 202
File
max(int|string $size)
Indicate that the uploaded file should be no more than the given number of kilobytes.
at line 214
File
encoding(string $encoding)
Indicate that the uploaded file should be in the given encoding.
at line 228
protected int|float
toKilobytes(int|string $size)
Convert a potentially human-friendly file size to kilobytes.
at line 252
File
rules(array|string|Stringable $rules)
Specify additional validation rules that should be merged with the default rules during validation.
at line 262
bool
passes(string $attribute, mixed $value)
Determine if the validation rule passes.
at line 283
protected array
buildValidationRules()
Build the array of underlying validation rules based on the current state.
at line 311
protected array
buildMimetypes()
Separate the given MIME types from extensions and return an array of correct rules to validate against.
at line 340
protected bool
fail(array|string $messages)
Adds the given failures, and return false.
at line 350
array|string
message()
Get the validation error message.
at line 360
ValidatorAwareRule
setValidator(Validator $validator)
Set the current validator.
at line 372
DataAwareRule
setData(array $data)
Set the current data under validation.
at line 382
static void
flushState()
Flush all static state.