Zend Framework  3.0
Public Member Functions | Public Attributes | Protected Attributes | List of all members
ValidatorChain Class Reference

Public Member Functions

 __construct ()
 Initialize validator chain.
 
 count ()
 Return the count of attached validators.
 
 getPluginManager ()
 Get plugin manager instance.
 
 setPluginManager (ValidatorPluginManager $plugins)
 Set plugin manager instance.
 
 plugin ($name, array $options=null)
 Retrieve a validator by name.
 
 attach (ValidatorInterface $validator, $breakChainOnFailure=false, $priority=self::DEFAULT_PRIORITY)
 Attach a validator to the end of the chain.
 
 addValidator (ValidatorInterface $validator, $breakChainOnFailure=false, $priority=self::DEFAULT_PRIORITY)
 Proxy to attach() to keep BC.
 
 prependValidator (ValidatorInterface $validator, $breakChainOnFailure=false)
 Adds a validator to the beginning of the chain.
 
 attachByName ($name, $options=[], $breakChainOnFailure=false, $priority=self::DEFAULT_PRIORITY)
 Use the plugin manager to add a validator by name.
 
 addByName ($name, $options=[], $breakChainOnFailure=false)
 Proxy to attachByName() to keep BC.
 
 prependByName ($name, $options=[], $breakChainOnFailure=false)
 Use the plugin manager to prepend a validator by name.
 
 isValid ($value, $context=null)
 Returns true if and only if $value passes all validations in the chain.
 
 merge (ValidatorChain $validatorChain)
 Merge the validator chain with the one given in parameter.
 
 getMessages ()
 Returns array of validation failure messages.
 
 getValidators ()
 Get all the validators.
 
 __invoke ($value)
 Invoke chain as command.
 
 __clone ()
 Deep clone handling.
 
 __sleep ()
 Prepare validator chain for serialization.
 
- Public Member Functions inherited from ValidatorInterface
 isValid ($value)
 Returns true if and only if $value meets the validation requirements.
 

Public Attributes

const DEFAULT_PRIORITY = 1
 Default priority at which validators are added.
 

Protected Attributes

 $plugins
 
 $validators
 
 $messages = []
 

Constructor & Destructor Documentation

__construct ( )

Initialize validator chain.

Member Function Documentation

__clone ( )

Deep clone handling.

__invoke (   $value)

Invoke chain as command.

Parameters
mixed$value
Returns
bool
__sleep ( )

Prepare validator chain for serialization.

Plugin manager (property 'plugins') cannot be serialized. On wakeup the property remains unset and next invocation to getPluginManager() sets the default plugin manager instance (ValidatorPluginManager).

Returns
array
addByName (   $name,
  $options = [],
  $breakChainOnFailure = false 
)

Proxy to attachByName() to keep BC.

Deprecated:
Please use attachByName()
Parameters
string$name
array$options
bool$breakChainOnFailure
Returns
ValidatorChain
addValidator ( ValidatorInterface  $validator,
  $breakChainOnFailure = false,
  $priority = self::DEFAULT_PRIORITY 
)

Proxy to attach() to keep BC.

Deprecated:
Please use attach()
Parameters
ValidatorInterface$validator
bool$breakChainOnFailure
int$priority
Returns
ValidatorChain Provides a fluent interface
attach ( ValidatorInterface  $validator,
  $breakChainOnFailure = false,
  $priority = self::DEFAULT_PRIORITY 
)

Attach a validator to the end of the chain.

If $breakChainOnFailure is true, then if the validator fails, the next validator in the chain, if one exists, will not be executed.

Parameters
ValidatorInterface$validator
bool$breakChainOnFailure
int$priorityPriority at which to enqueue validator; defaults to 1 (higher executes earlier)
Exceptions
Exception\InvalidArgumentException
Returns
self
attachByName (   $name,
  $options = [],
  $breakChainOnFailure = false,
  $priority = self::DEFAULT_PRIORITY 
)

Use the plugin manager to add a validator by name.

Parameters
string$name
array$options
bool$breakChainOnFailure
int$priority
Returns
ValidatorChain
count ( )

Return the count of attached validators.

Returns
int
getMessages ( )

Returns array of validation failure messages.

Returns
array

Implements ValidatorInterface.

getPluginManager ( )

Get plugin manager instance.

Returns
ValidatorPluginManager
getValidators ( )

Get all the validators.

Returns
array
isValid (   $value,
  $context = null 
)

Returns true if and only if $value passes all validations in the chain.

Validators are run in the order in which they were added to the chain (FIFO).

Parameters
mixed$value
mixed$contextExtra "context" to provide the validator
Returns
bool
merge ( ValidatorChain  $validatorChain)

Merge the validator chain with the one given in parameter.

Parameters
ValidatorChain$validatorChain
Returns
ValidatorChain
plugin (   $name,
array  $options = null 
)

Retrieve a validator by name.

Parameters
string$nameName of validator to return
null | array$optionsOptions to pass to validator constructor (if not already instantiated)
Returns
ValidatorInterface
prependByName (   $name,
  $options = [],
  $breakChainOnFailure = false 
)

Use the plugin manager to prepend a validator by name.

Parameters
string$name
array$options
bool$breakChainOnFailure
Returns
ValidatorChain
prependValidator ( ValidatorInterface  $validator,
  $breakChainOnFailure = false 
)

Adds a validator to the beginning of the chain.

If $breakChainOnFailure is true, then if the validator fails, the next validator in the chain, if one exists, will not be executed.

Parameters
ValidatorInterface$validator
bool$breakChainOnFailure
Returns
ValidatorChain Provides a fluent interface
setPluginManager ( ValidatorPluginManager  $plugins)

Set plugin manager instance.

Parameters
ValidatorPluginManager$pluginsPlugin manager
Returns
ValidatorChain

Member Data Documentation

$messages = []
protected
$plugins
protected
$validators
protected
const DEFAULT_PRIORITY = 1

Default priority at which validators are added.