Methods

Validation method is the process used to confirm that the procedure employed for a specific test is suitable for its intended use.


Method Interface

Describes Method interface.

getMethods

Retrieves all validation method values.

$methods = $validation->getMethods();

hasMethod

Checks if a method exists by the given case-sensitive name.

$has_method = $validation->hasMethod($name);

getMethod

Retrieve a validation method callback by the given case-sensitive name.

$callback = $validation->getMethod($name);

withMethod

Return an instance with the provided callback replacing the specified method.

$callback = function(mixed $expect, mixed $actual, array $data): bool{
    ...
};

$validation = $validation->withMethod($name, $callback);

withoutMethod

Return an instance without the specified method.

$validation = $validation->withoutMethod($name);

Build-In Methods

NameExpectActualDescription
requiredboolmixedMakes the actual value required.
emptyboolmixedMakes the actual value require an empty value.
not-emptyboolmixedMakes the actual value require not an empty value.
lengthintstringMakes the actual value require a given length.
length-minintstringMakes the actual value require a given minimum length.
length-maxintstringMakes the actual value require a given maximum length.
sizeintarrayMakes the actual value require a given size.
size-minintarrayMakes the actual value require a given minimum size.
size-maxintarrayMakes the actual value require a given maximum size.
minnumericnumericMakes the actual value require a given minimum value.
maxnumericnumericMakes the actual value require a given maximum value.
formatstringstringMakes the actual value require a given format.
regexstringstringMakes the actual value match with the given expression.
typestringmixedMakes the actual value require a given type.
not-typestringmixedMakes the actual value require not a given type.
equalstringmixedMakes the actual value to be the same as another data value.
not-equalstringmixedMakes the actual value to be different with another data value.
inarraymixedMakes the actual value to be present in list.
not-inarraymixedMakes the actual value to be absent in list.
valuemixedmixedMakes the actual value require a given value.
not-valuemixedmixedMakes the actual value require not a given value.

Possible values for type are:

  • null
  • boolean
  • integer
  • double
  • string
  • array
  • object
  • resource
  • unknown type

Possible values for format are:

  • domain
  • email
  • url
  • ip
  • ip4
  • ip6
  • mac
  • date
  • datetime
  • date-atom
  • date-cookie
  • date-rfc822
  • date-rfc850
  • date-rfc1036
  • date-rfc1123
  • date-rfc7231
  • date-rfc2822
  • date-rfc3339
  • date-rfc3339-expanded
  • date-rss
  • date-w3c