Pionia Core

Validator
in package
Uses ValidationTrait

This class is used to validate data

Table of Contents

Properties

$hayStack  : Arrayable|null
$hook  : string
The hook to validate
$ip_pattern  : string
$password_pattern  : string
$phone_pattern  : string
$slug_pattern  : string
$throwsExceptions  : bool

Methods

are()  : Validator
array()  : static
Ensures that the field is an array
asDomain()  : Validator
asEmail()  : Validator
Validates emails of all formats
asInternationalPhone()  : bool|int
Will only validate international numbers if the code is provided, otherwise, will validate local only
asIp()  : Validator
asMac()  : Validator
asNumber()  : static
asNumeric()  : static
asNumericInt()  : static
asPassword()  : static
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()  : Validator
asUrl()  : Validator
bool()  : static
Ensures that the field is a boolean
date()  : static
Ensures that the field is a date
doesNotMatch()  : static
Check if the value of the field is not equal to the value of another field
email()  : static
Ensures that the field is an email
float()  : static
Ensures that the field is a float
get()  : Validator
Get the value of hook
int()  : static
Ensures that the field is an integer
matches()  : static
Check if the value of the field is equal to the value of another field
required()  : static
Marks the field as required
requiredIf()  : Validator
Required if the condition is met by the hook
requiredUnless()  : static
Required unless the condition is met by the field
requiredWith()  : static
Only required if the field is present/defined
requiredWithout()  : static
Only required if the field is not present/defined
string()  : static
Ensures that the field is a string
validate()  : static
valueOf()  : Validator
Get the value of hook
_validate()  : bool|int
Use this to cover scenarios this contract does not cover
_validateFilter()  : int|bool
Internal validator based on PHP filter_var validations
getOrFail()  : mixed
is()  : Validator
Check if the value matches the expected value

Properties

$hook

The hook to validate

protected string $hook

$ip_pattern

private string $ip_pattern = "/^(\\d{1,3}\\.){3}\\d{1,3}\$/"

$password_pattern

private string $password_pattern = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*(_|[^\\w])).+\$/"

$phone_pattern

private string $phone_pattern = "/^[+]{1}(?:[0-9\\-\\(\\)\\/.]\\s?){6,15}[0-9]{1}\$/"

Methods

are()

public are(string $expected[, string|null $message = 'Invalid data' ]) : Validator
Parameters
$expected : string
$message : string|null = 'Invalid data'
Tags
throws
Exception
Return values
Validator

array()

Ensures that the field is an array

public array([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

asDomain()

public asDomain([string|null $regex = null ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

Tags
throws
Exception
Return values
Validator

asEmail()

Validates emails of all formats

public asEmail([string|null $regex = null ][, string|null $message = 'Invalid email address' ]) : Validator
Parameters
$regex : string|null = null
$message : string|null = 'Invalid email address'
Tags
throws
Exception
Return values
Validator

asInternationalPhone()

Will only validate international numbers if the code is provided, otherwise, will validate local only

public asInternationalPhone([string|null $code = null ][, string|null $regex = null ][, string|null $message = 'Invalid phone number' ]) : bool|int
Parameters
$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.

$message : string|null = 'Invalid phone number'
Tags
throws
Exception
Return values
bool|int

asIp()

public asIp([string|null $regex = null ][, string|null $message = 'Invalid IP address' ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid IP address'
Tags
throws
Exception
Return values
Validator

asMac()

public asMac([string|null $regex = null ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

Tags
throws
Exception
Return values
Validator

asNumber()

public asNumber([string|null $message = 'Invalid Number' ]) : static
Parameters
$message : string|null = 'Invalid Number'
Tags
throws
Exception
Return values
static

asNumeric()

public asNumeric([string|null $message = 'Invalid Numeric' ]) : static
Parameters
$message : string|null = 'Invalid Numeric'
Tags
throws
Exception
Return values
static

asNumericInt()

public asNumericInt([string|null $message = 'Invalid Numeric Integer' ]) : static
Parameters
$message : string|null = 'Invalid Numeric Integer'
Tags
throws
Exception
Return values
static

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([string|null $regex = null ][, string|null $message = 'Week Password' ]) : static
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

$message : string|null = 'Week Password'
Tags
throws
Exception
Return values
static

asSlug()

public asSlug([string|null $regex = null ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

Tags
throws
Exception
example
$slug = 'fsjkfjshfsjk-skdhfkjdfsj-skdjfhjskdf'; // valid slug
$slug2 = 'sfksdfsdskljfhsdhjkfhsdsfsdfsfsd'; // valid slug
$slug3 = 'dkfl ksjfhsdk/skjdfsk%'; // invalid slug
Return values
Validator

asUrl()

public asUrl([string|null $regex = null ][, string|null $message = 'Invalid URL' ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid URL'
Tags
throws
Exception
Return values
Validator

bool()

Ensures that the field is a boolean

public bool([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

date()

Ensures that the field is a date

public date([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

doesNotMatch()

Check if the value of the field is not equal to the value of another field

public doesNotMatch(string $field[, string|null $message = null ]) : static
Parameters
$field : string
$message : string|null = null
Tags
throws
Exception
Return values
static

email()

Ensures that the field is an email

public email([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

float()

Ensures that the field is a float

public float([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

int()

Ensures that the field is an integer

public int([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

matches()

Check if the value of the field is equal to the value of another field

public matches(string $field[, string|null $message = null ]) : static
Parameters
$field : string
$message : string|null = null
Tags
throws
Exception
Return values
static

required()

Marks the field as required

public required([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

requiredIf()

Required if the condition is met by the hook

public requiredIf(string $field, callable $condition) : Validator
Parameters
$field : string
$condition : callable

The condition to check against. Receives the instance of the validator

Tags
throws
Exception
Return values
Validator

requiredUnless()

Required unless the condition is met by the field

public requiredUnless(string $field, callable $condition) : static
Parameters
$field : string
$condition : callable
Tags
throws
Exception
Return values
static

requiredWith()

Only required if the field is present/defined

public requiredWith(string $field) : static
Parameters
$field : string
Tags
throws
Exception
Return values
static

requiredWithout()

Only required if the field is not present/defined

public requiredWithout(string $field) : static
Parameters
$field : string
Tags
throws
Exception
Return values
static

string()

Ensures that the field is a string

public string([string|null $message = null ]) : static
Parameters
$message : string|null = null
Tags
throws
Exception
Return values
static

validate()

public static validate(string $keyToValidate, Arrayable|null $data) : static
Parameters
$keyToValidate : string
$data : Arrayable|null
Return values
static

_validate()

Use this to cover scenarios this contract does not cover

private _validate(string $regex[, string|null $message = 'Invalid data' ]) : bool|int
Parameters
$regex : string
  • The regular expression to check against
$message : string|null = 'Invalid data'
  • The message to throw if the value is invalid and we are in the exceptions mode
Tags
throws
Exception
Return values
bool|int

_validateFilter()

Internal validator based on PHP filter_var validations

private _validateFilter( $filterType[, string $message = 'Invalid Data' ]) : int|bool
Parameters
$filterType :
$message : string = 'Invalid Data'
Tags
throws
Exception
Return values
int|bool

is()

Check if the value matches the expected value

private is(string $expected[, string|null $message = 'Invalid data' ]) : Validator
Parameters
$expected : string
$message : string|null = 'Invalid data'
Tags
throws
Exception
Return values
Validator

        
On this page

Search results