PHP Class Garden\Validation

Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Свойство Type Description
$errors Properties ///
$mainMessage
$status

Méthodes publiques

Méthode Description
__construct ( array $errors = [], string $mainMessage = '', integer $status ) Initialize an instance of the {@link Validation} class.
addError ( string $messageCode, string | array $field = '*', integer | array $options = [] ) : Validation Add an error.
errorMessage ( array $error ) : string Gets the error message from an error.
fieldValid ( string $field ) : boolean Check whether or not a particular field is has errors.
getErrorsFlat ( ) : array Gets all of the errors as a flat array.
getMessage ( ) : string Get the message for this exception.
isValid ( ) : boolean Check whether or not the validation is free of errors.
mainMessage ( string | null $value = null ) : Validation | string Gets the main error message for the validation.
status ( integer | null $value = null ) : Validation | integer Get or set the error status code.

Private Methods

Méthode Description
arraySelect ( array $keys, array $array, mixed $default = null ) : mixed Select the first non-empty value from an array.

Method Details

__construct() public méthode

Initialize an instance of the {@link Validation} class.
public __construct ( array $errors = [], string $mainMessage = '', integer $status )
$errors array An array of errors.
$mainMessage string The main message of the error.
$status integer The http status code of the error or 0 to build the status code from the indivdual errors.

addError() public méthode

Add an error.
public addError ( string $messageCode, string | array $field = '*', integer | array $options = [] ) : Validation
$messageCode string The message translation code. If you add a message that starts with "@" then no translation will take place.
$field string | array The name of the field to add or an array of fields if the error applies to more than one field.
$options integer | array An array of additional information to add to the error entry or a numeric error code.
Résultat Validation Returns $this for fluent calls.

errorMessage() public static méthode

Errors are stored with either a message or a translation code. This method will look at both to determine the full message.
public static errorMessage ( array $error ) : string
$error array The error array.
Résultat string Returns the message from the error.

fieldValid() public méthode

Check whether or not a particular field is has errors.
public fieldValid ( string $field ) : boolean
$field string The name of the field to check for validity.
Résultat boolean Returns true if the field has no errors, false otherwise.

getErrorsFlat() public méthode

The errors are internally stored indexed by field. This method flattens them for final error returns.
public getErrorsFlat ( ) : array
Résultat array Returns all of the errors.

getMessage() public méthode

Get the message for this exception.
public getMessage ( ) : string
Résultat string Returns the exception message.

isValid() public méthode

Check whether or not the validation is free of errors.
public isValid ( ) : boolean
Résultat boolean Returns true if there are no errors, false otherwise.

mainMessage() public méthode

Gets the main error message for the validation.
public mainMessage ( string | null $value = null ) : Validation | string
$value string | null Pass a new main message or null to get the current main message.
Résultat Validation | string Returns the main message or $this for fluent sets.

status() public méthode

The status code is an http resonse code and should be of the 4xx variety.
public status ( integer | null $value = null ) : Validation | integer
$value integer | null Pass a new status code or null to get the current code.
Résultat Validation | integer Returns the current status code or $this for fluent sets.

Property Details

$errors protected_oe property

Properties ///
protected $errors

$mainMessage protected_oe property

protected $mainMessage

$status protected_oe property

protected $status