class ImageFile extends File (View source)

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 null|int $minimumFileSize

The minimum size in kilobytes that the file can be.

from  File
protected null|int $maximumFileSize

The maximum size in kilobytes that the file can be.

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 $validator

The validator performing the validation.

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

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

from  File

Methods

$this|TWhenReturnType
when($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

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

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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(File|callable|null $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()

Limit the uploaded file to only image types.

from  File
static File
types(string|array<int,string> $mimetypes)

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

from  File
$this
size(int $kilobytes)

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

from  File
$this
between(int $minKilobytes, int $maxKilobytes)

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

from  File
$this
min(int $kilobytes)

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

from  File
$this
max(int $kilobytes)

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

from  File
$this
rules(string|array $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
string|array
message()

Get the validation error message.

from  File
$this
setValidator(Validator $validator)

Set the current validator.

from  File
$this
setData(array $data)

Set the current data under validation.

from  File
void
__construct()

Create a new image file rule instance.

dimensions(Dimensions $dimensions)

The dimension constraints for the uploaded file.

Details

$this|TWhenReturnType when($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

$value
callable $callback
callable $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless($value = null, callable $callback = null, callable $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

$value
callable $callback
callable $default

Return Value

$this|TUnlessReturnType

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

static File|null defaults(File|callable|null $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.

Parameters

File|callable|null $callback

Return Value

File|null

static File default()

Get the default configuration of the file rule.

Return Value

File

static ImageFile image()

Limit the uploaded file to only image types.

Return Value

ImageFile

static File types(string|array<int,string> $mimetypes)

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

Parameters

string|array<int,string> $mimetypes

Return Value

File

$this size(int $kilobytes)

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

Parameters

int $kilobytes

Return Value

$this

$this between(int $minKilobytes, int $maxKilobytes)

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

Parameters

int $minKilobytes
int $maxKilobytes

Return Value

$this

$this min(int $kilobytes)

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

Parameters

int $kilobytes

Return Value

$this

$this max(int $kilobytes)

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

Parameters

int $kilobytes

Return Value

$this

$this rules(string|array $rules)

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

Parameters

string|array $rules

Return Value

$this

bool passes(string $attribute, mixed $value)

Determine if the validation rule passes.

Parameters

string $attribute
mixed $value

Return Value

bool

protected array buildValidationRules()

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

Return Value

array

protected array buildMimetypes()

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

Return Value

array

protected bool fail(array|string $messages)

Adds the given failures, and return false.

Parameters

array|string $messages

Return Value

bool

string|array message()

Get the validation error message.

Return Value

string|array

$this setValidator(Validator $validator)

Set the current validator.

Parameters

Validator $validator

Return Value

$this

$this setData(array $data)

Set the current data under validation.

Parameters

array $data

Return Value

$this

void __construct()

Create a new image file rule instance.

Return Value

void

dimensions(Dimensions $dimensions)

The dimension constraints for the uploaded file.

Parameters

Dimensions $dimensions