Pionia Core

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}\$/"

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

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
throws
InvalidDataException
Return values
bool|int

asEmail()

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
throws
InvalidDataException
Return values
bool|int

asInternationalPhone()

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
throws
InvalidDataException
Return values
bool|int

asIp()

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
throws
InvalidDataException
Return values
bool|int

asMac()

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
throws
InvalidDataException
Return values
bool|int

asPassword()

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
throws
InvalidDataException
Return values
bool|int

asSlug()

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
example
$slug = 'fsjkfjshfsjk-skdhfkjdfsj-skdjfhjskdf'; // valid slug
$slug2 = 'sfksdfsdskljfhsdhjkfhsdsfsdfsfsd'; // valid slug
$slug3 = 'dkfl ksjfhsdk/skjdfsk%'; // invalid slug
throws
InvalidDataException
Return values
bool|int

asUrl()

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
throws
InvalidDataException
Return values
bool|int

validate()

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
throws
InvalidDataException
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
$value : mixed
$filterType :
$message : string = 'Invalid Data'
Tags
throws
InvalidDataException
Return values
int|bool

        
On this page

Search results