PHP Class Sirius\Validation\Validator

Inheritance: implements Sirius\Validation\ValidatorInterface
Mostrar archivo Open project: siriusphp/validation Class Usage Examples

Protected Properties

Property Type Description
$dataWrapper Sirius\Validation\DataWrapper\WrapperInterface The object that will contain the data
$errorMessagePrototype Sirius\Validation\ErrorMessage
$messages array
$ruleFactory RuleFactory
$rules array
$wasValidated boolean

Public Methods

Method Description
__construct ( RuleFactory $ruleFactory = null, Sirius\Validation\ErrorMessage $errorMessagePrototype = null )
add ( string $selector, string | callback $name = null, string | array $options = null, string $messageTemplate = null, string $label = null ) : Validator
addMessage ( string $item, string $message = null ) : self
addMultiple ( array $selectorRulesCollection ) : Validator
clearMessages ( string $item = null ) : self Clears the messages of an item
getDataWrapper ( mixed $data = null ) : Sirius\Validation\DataWrapper\WrapperInterface The data wrapper will be used to wrap around the data passed to the validator This way you can validate anything, not just arrays (which is the default)
getErroMessagePrototype ( ) : Sirius\Validation\ErrorMessage Retrieve the error message prototype
getMessages ( string $item = null ) : array
getRuleFactory ( ) : RuleFactory Retrieve the rule factory
getRules ( )
remove ( string $selector, mixed $name = true, mixed $options = null ) : self
setData ( $data )
setErrorMessagePrototype ( Sirius\Validation\ErrorMessage $errorMessagePrototype ) : Sirius\Validation\Rule\AbstractValidator
validate ( mixed $data = null ) : boolean Performs the validation

Protected Methods

Method Description
ensureSelectorRulesExist ( string $selector, string $label = null )

Method Details

__construct() public method

public __construct ( RuleFactory $ruleFactory = null, Sirius\Validation\ErrorMessage $errorMessagePrototype = null )
$ruleFactory RuleFactory
$errorMessagePrototype Sirius\Validation\ErrorMessage

add() public method

public add ( string $selector, string | callback $name = null, string | array $options = null, string $messageTemplate = null, string $label = null ) : Validator
$selector string
$name string | callback
$options string | array
$messageTemplate string
$label string
return Validator

addMessage() public method

public addMessage ( string $item, string $message = null ) : self
$item string data identifier (eg: 'email', 'addresses[0][state]')
$message string
return self

addMultiple() public method

public addMultiple ( array $selectorRulesCollection ) : Validator
$selectorRulesCollection array
return Validator

clearMessages() public method

Clears the messages of an item
public clearMessages ( string $item = null ) : self
$item string
return self

ensureSelectorRulesExist() protected method

protected ensureSelectorRulesExist ( string $selector, string $label = null )
$selector string
$label string

getDataWrapper() public method

The data wrapper will be used to wrap around the data passed to the validator This way you can validate anything, not just arrays (which is the default)
public getDataWrapper ( mixed $data = null ) : Sirius\Validation\DataWrapper\WrapperInterface
$data mixed
return Sirius\Validation\DataWrapper\WrapperInterface

getErroMessagePrototype() public method

Retrieve the error message prototype
public getErroMessagePrototype ( ) : Sirius\Validation\ErrorMessage
return Sirius\Validation\ErrorMessage

getMessages() public method

public getMessages ( string $item = null ) : array
$item string key of the messages array (eg: 'password', 'addresses[0][line_1]')
return array

getRuleFactory() public method

Retrieve the rule factory
public getRuleFactory ( ) : RuleFactory
return RuleFactory

getRules() public method

public getRules ( )

remove() public method

public remove ( string $selector, mixed $name = true, mixed $options = null ) : self
$selector string data selector
$name mixed rule name or true if all rules should be deleted for that selector
$options mixed rule options, necessary for rules that depend on params for their ID
return self

setData() public method

public setData ( $data )

setErrorMessagePrototype() public method

public setErrorMessagePrototype ( Sirius\Validation\ErrorMessage $errorMessagePrototype ) : Sirius\Validation\Rule\AbstractValidator
$errorMessagePrototype Sirius\Validation\ErrorMessage
return Sirius\Validation\Rule\AbstractValidator

validate() public method

Performs the validation
public validate ( mixed $data = null ) : boolean
$data mixed array to be validated
return boolean

Property Details

$dataWrapper protected_oe property

The object that will contain the data
protected WrapperInterface,Sirius\Validation\DataWrapper $dataWrapper
return Sirius\Validation\DataWrapper\WrapperInterface

$errorMessagePrototype protected_oe property

protected ErrorMessage,Sirius\Validation $errorMessagePrototype
return Sirius\Validation\ErrorMessage

$messages protected_oe property

protected array $messages
return array

$ruleFactory protected_oe property

protected RuleFactory,Sirius\Validation $ruleFactory
return RuleFactory

$rules protected_oe property

protected array $rules
return array

$wasValidated protected_oe property

protected bool $wasValidated
return boolean