ValidationTrait
Table of Contents
Properties
- $ip_pattern : string
- $password_pattern : string
- $phone_pattern : string
- $slug_pattern : string
- $throwsExceptions : bool
Methods
- __construct() : mixed
- allShouldBe() : mixed
- asDomain() : bool|int
- asEmail() : bool|int
- Validates emails of all formats
- asInternationalPhone() : bool|int
- Will only validate international numbers if the code is provided, otherwise, will validate local only
- asIp() : bool|int
- asMac() : bool|int
- asNumber() : bool
- asNumeric() : bool|int
- asNumericInt() : bool|int
- asPassword() : bool|int
- Validates the rules as follows - At least one integer - At least one lowercase alpha letter - At least one Uppercase alpha letter - At least one special character
- asSlug() : bool|int
- asUrl() : bool|int
- validate() : bool|int
- Use this to cover scenarios this contract does not cover
- _validateFilter() : int|bool
- Internal validator based on PHP filter_var validations
- shouldBe() : bool
Properties
$ip_pattern
public
string
$ip_pattern
= "/^(\\d{1,3}\\.){3}\\d{1,3}\$/"
$password_pattern
public
string
$password_pattern
= "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*(_|[^\\w])).+\$/"
$phone_pattern
public
string
$phone_pattern
= "/^[+]{1}(?:[0-9\\-\\(\\)\\/.]\\s?){6,15}[0-9]{1}\$/"
$slug_pattern
public
string
$slug_pattern
= "/^[a-z0-9-]+\$/"
$throwsExceptions
private
bool
$throwsExceptions
= true
Methods
__construct()
public
__construct([mixed $throws = true ]) : mixed
Parameters
- $throws : mixed = true
allShouldBe()
public
allShouldBe(iterable<string|int, mixed> $value, string $expected) : mixed
Parameters
- $value : iterable<string|int, mixed>
- $expected : string
Tags
asDomain()
public
asDomain(mixed $domain[, string|null $regex = null ]) : bool|int
Parameters
- $domain : mixed
-
The domain we are testing its validity
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
bool|intasEmail()
Validates emails of all formats
public
asEmail(string $email) : bool|int
Parameters
- $email : string
-
The email address we're currently testing in the core.
Tags
Return values
bool|intasInternationalPhone()
Will only validate international numbers if the code is provided, otherwise, will validate local only
public
asInternationalPhone(string $phone[, string|null $code = null ][, string|null $regex = null ]) : bool|int
Parameters
- $phone : string
-
The phone number we are testing
- $code : string|null = null
-
International country that you want to check against
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
bool|intasIp()
public
asIp(mixed $ip[, string|null $regex = null ]) : bool|int
Parameters
- $ip : mixed
-
The Ip address we're checking.
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
bool|intasMac()
public
asMac(mixed $mac[, string|null $regex = null ]) : bool|int
Parameters
- $mac : mixed
-
The mac address we are checking
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
bool|intasNumber()
public
asNumber(mixed $number) : bool
Parameters
- $number : mixed
-
The number we are checking
Tags
Return values
boolasNumeric()
public
asNumeric(mixed $number) : bool|int
Parameters
- $number : mixed
Tags
Return values
bool|intasNumericInt()
public
asNumericInt(mixed $number) : bool|int
Parameters
- $number : mixed
Tags
Return values
bool|intasPassword()
Validates the rules as follows - At least one integer - At least one lowercase alpha letter - At least one Uppercase alpha letter - At least one special character
public
asPassword(mixed $password[, string|null $regex = null ]) : bool|int
Parameters
- $password : mixed
-
The password string we are testing, must be raw, not hashed
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
bool|intasSlug()
public
asSlug(mixed $slug[, string|null $regex = null ]) : bool|int
Parameters
- $slug : mixed
-
The slug string we are testing
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
bool|intasUrl()
public
asUrl(mixed $url[, string|null $regex = null ]) : bool|int
Parameters
- $url : mixed
-
The url string we are testing
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
bool|intvalidate()
Use this to cover scenarios this contract does not cover
public
validate(string $regex, mixed $value[, string|null $message = 'Invalid data' ]) : bool|int
Parameters
- $regex : string
-
- The regular expression to check against
- $value : mixed
-
- The value to check
- $message : string|null = 'Invalid data'
-
- The message to throw if the value is invalid and we are in the exceptions mode
Tags
Return values
bool|int_validateFilter()
Internal validator based on PHP filter_var validations
private
_validateFilter(mixed $value, $filterType[, string $message = 'Invalid Data' ]) : int|bool
Parameters
Tags
Return values
int|boolshouldBe()
private
shouldBe(mixed $value, mixed $expected) : bool
Parameters
- $value : mixed
- $expected : mixed