class Email implements Rule, DataAwareRule, ValidatorAwareRule (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
$validateMxRecord
$preventSpoofing
$nativeValidation
$nativeValidationWithUnicodeAllowed
$rfcCompliant
$strictRfcCompliant
protected Validator $validator

The validator performing the validation.

protected array $data

The data under validation.

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.

static string|array|callable|null $defaultCallback

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

Methods

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

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

$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $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 Email|void
defaults(Email|callable|null $callback = null)

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

static Email
default()

Get the default configuration of the file rule.

$this
rfcCompliant(bool $strict = false)

Ensure that the email is an RFC compliant email address.

$this
strict()

Ensure that the email is a strictly enforced RFC compliant email address.

$this
validateMxRecord()

Ensure that the email address has a valid MX record.

$this
preventSpoofing()

Ensure that the email address is not attempting to spoof another email address using invalid unicode characters.

$this
withNativeValidation(bool $allowUnicode = false)

Ensure the email address is valid using PHP's native email validation functions.

$this
rules(string|array $rules)

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

bool
passes(string $attribute, mixed $value)

Determine if the validation rule passes.

array
buildValidationRules()

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

bool
fail(array|string $messages)

Adds the given failures, and return false.

string|array
message()

Get the validation error message.

$this
setValidator(Validator $validator)

Set the current validator.

$this
setData(array $data)

Set the current data under validation.

Details

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

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

Parameters

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

Return Value

$this|TWhenReturnType

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

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

Parameters

$value
callable|null $callback
callable|null $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 Email|void defaults(Email|callable|null $callback = null)

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

If no arguments are passed, the default email rule configuration will be returned.

Parameters

Email|callable|null $callback

Return Value

Email|void

static Email default()

Get the default configuration of the file rule.

Return Value

Email

$this rfcCompliant(bool $strict = false)

Ensure that the email is an RFC compliant email address.

Parameters

bool $strict

Return Value

$this

$this strict()

Ensure that the email is a strictly enforced RFC compliant email address.

Return Value

$this

$this validateMxRecord()

Ensure that the email address has a valid MX record.

Requires the PHP intl extension.

Return Value

$this

$this preventSpoofing()

Ensure that the email address is not attempting to spoof another email address using invalid unicode characters.

Return Value

$this

$this withNativeValidation(bool $allowUnicode = false)

Ensure the email address is valid using PHP's native email validation functions.

Parameters

bool $allowUnicode

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