class ImageFile extends File

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.

from  File
protected array $allowedExtensions

The extensions that the given file should match.

from  File
protected int|null $minimumFileSize

The minimum size in kilobytes that the file can be.

from  File
protected int|null $maximumFileSize

The maximum size in kilobytes that the file can be.

from  File
protected string|null $encoding

The required file encoding.

from  File
protected array $customRules

An array of custom rules that will be merged into the validation rules.

from  File
protected array $messages

The error message after validation, if any.

from  File
protected array $data

The data under validation.

from  File
protected Validator|null $validator

The validator performing the validation.

from  File
static null|array|callable|string $defaultCallback

The callback that will generate the "default" version of the file rule.

from  File

Methods

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.

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.

void
__clone()

Clone the nested executable rule objects.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

static File|null
defaults(mixed $callback = null)

Set the default callback to be used for determining the file default rules.

from  File
static File
default()

Get the default configuration of the file rule.

from  File
static ImageFile
image(bool $allowSvg = false)

Limit the uploaded file to only image types.

from  File
static File
types(array|string $mimetypes)

Limit the uploaded file to the given MIME types or file extensions.

from  File
extensions(array|string $extensions)

Limit the uploaded file to the given file extensions.

from  File
size(int|string $size)

Indicate that the uploaded file should be exactly a certain size in kilobytes.

from  File
between(int|string $minSize, int|string $maxSize)

Indicate that the uploaded file should be between a minimum and maximum size in kilobytes.

from  File
min(int|string $size)

Indicate that the uploaded file should be no less than the given number of kilobytes.

from  File
max(int|string $size)

Indicate that the uploaded file should be no more than the given number of kilobytes.

from  File
encoding(string $encoding)

Indicate that the uploaded file should be in the given encoding.

from  File
mixed
toKilobytes(int|string $size)

Convert a potentially human-friendly file size to kilobytes.

from  File
rules(array|string|Stringable $rules)

Specify additional validation rules that should be merged with the default rules during validation.

from  File
bool
passes(string $attribute, mixed $value)

Determine if the validation rule passes.

from  File
array
buildValidationRules()

Build the array of underlying validation rules based on the current state.

from  File
array
buildMimetypes()

Separate the given mimetypes from extensions and return an array of correct rules to validate against.

from  File
bool
fail(array|string $messages)

Adds the given failures, and return false.

from  File
array|string
message()

Get the validation error message.

from  File
setValidator(Validator $validator)

Set the current validator.

from  File
setData(array $data)

Set the current data under validation.

from  File
static void
flushState()

Flush all static state.

from  File
__construct(bool $allowSvg = false)

Create a new image file rule instance.

dimensions(Dimensions $dimensions)

The dimension constraints for the uploaded file.

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

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.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in ClonesCustomRules at line 16
void __clone()

Clone the nested executable rule objects.

Return Value

void

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in File at line 89
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.

Boot-only when setting. The default callback persists in a static property for the worker lifetime and is used by every File::default() call across all coroutines.

Parameters

mixed $callback

Return Value

File|null

in File at line 107
static File default()

Get the default configuration of the file rule.

Return Value

File

in File at line 127
static ImageFile image(bool $allowSvg = false)

Limit the uploaded file to only image types.

Parameters

bool $allowSvg

Return Value

ImageFile

in File at line 137
static File types(array|string $mimetypes)

Limit the uploaded file to the given MIME types or file extensions.

Parameters

array|string $mimetypes

Return Value

File

in File at line 145
File extensions(array|string $extensions)

Limit the uploaded file to the given file extensions.

Parameters

array|string $extensions

Return Value

File

in File at line 155
File size(int|string $size)

Indicate that the uploaded file should be exactly a certain size in kilobytes.

Parameters

int|string $size

Return Value

File

in File at line 166
File between(int|string $minSize, int|string $maxSize)

Indicate that the uploaded file should be between a minimum and maximum size in kilobytes.

Parameters

int|string $minSize
int|string $maxSize

Return Value

File

in File at line 177
File min(int|string $size)

Indicate that the uploaded file should be no less than the given number of kilobytes.

Parameters

int|string $size

Return Value

File

in File at line 187
File max(int|string $size)

Indicate that the uploaded file should be no more than the given number of kilobytes.

Parameters

int|string $size

Return Value

File

in File at line 197
File encoding(string $encoding)

Indicate that the uploaded file should be in the given encoding.

Parameters

string $encoding

Return Value

File

in File at line 207
protected mixed toKilobytes(int|string $size)

Convert a potentially human-friendly file size to kilobytes.

Parameters

int|string $size

Return Value

mixed

in File at line 229
File rules(array|string|Stringable $rules)

Specify additional validation rules that should be merged with the default rules during validation.

Parameters

array|string|Stringable $rules

Return Value

File

in File at line 239
bool passes(string $attribute, mixed $value)

Determine if the validation rule passes.

Parameters

string $attribute
mixed $value

Return Value

bool

in File at line 260
protected array buildValidationRules()

Build the array of underlying validation rules based on the current state.

Return Value

array

in File at line 288
protected array buildMimetypes()

Separate the given mimetypes from extensions and return an array of correct rules to validate against.

Return Value

array

in File at line 317
protected bool fail(array|string $messages)

Adds the given failures, and return false.

Parameters

array|string $messages

Return Value

bool

in File at line 327
array|string message()

Get the validation error message.

Return Value

array|string

in File at line 335
ValidatorAwareRule setValidator(Validator $validator)

Set the current validator.

Parameters

Validator $validator

Return Value

ValidatorAwareRule

in File at line 345
DataAwareRule setData(array $data)

Set the current data under validation.

Parameters

array $data

Return Value

DataAwareRule

in File at line 355
static void flushState()

Flush all static state.

Return Value

void

at line 12
__construct(bool $allowSvg = false)

Create a new image file rule instance.

Parameters

bool $allowSvg

at line 24
ImageFile dimensions(Dimensions $dimensions)

The dimension constraints for the uploaded file.

Parameters

Dimensions $dimensions

Return Value

ImageFile