PHP Class Garden\Validation

Datei anzeigen Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Property Type Description
$errors Properties ///
$mainMessage
$status

Public Methods

Method 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

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

Method Details

__construct() public method

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 method

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.
return Validation Returns $this for fluent calls.

errorMessage() public static method

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.
return string Returns the message from the error.

fieldValid() public method

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.
return boolean Returns true if the field has no errors, false otherwise.

getErrorsFlat() public method

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

getMessage() public method

Get the message for this exception.
public getMessage ( ) : string
return string Returns the exception message.

isValid() public method

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

mainMessage() public method

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.
return Validation | string Returns the main message or $this for fluent sets.

status() public method

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.
return 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