ValidatorChain
in package
implements
Countable, IteratorAggregate, ValidatorInterface
Tags
Table of Contents
Interfaces
- Countable
- IteratorAggregate
- ValidatorInterface
Constants
- DEFAULT_PRIORITY = 1
- Default priority at which validators are added
Properties
- $messages : array<string, string>
- Array of validation failure messages
- $plugins : ValidatorPluginManager<string|int, ValidatorInterface>|null
- $validators : PriorityQueue<QueueElement, int>
- Validator chain
Methods
- __clone() : mixed
- Deep clone handling
- __construct() : mixed
- Initialize validator chain
- __invoke() : bool
- Invoke chain as command
- __sleep() : array<string|int, mixed>
- Prepare validator chain for serialization
- addByName() : ValidatorChain
- Proxy to attachByName() to keep BC
- addValidator() : ValidatorChain
- Proxy to attach() to keep BC
- attach() : $this
- 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.
- attachByName() : $this
- Use the plugin manager to add a validator by name
- count() : int
- Return the count of attached validators
- getIterator() : Traversable<string|int, QueueElement>
- getMessages() : array<string, string>
- Returns array of validation failure messages
- getPluginManager() : ValidatorPluginManager<string|int, ValidatorInterface>
- Get plugin manager instance
- getValidators() : array<int, QueueElement>
- Get all the validators
- isValid() : bool
- Returns true if and only if $value passes all validations in the chain
- merge() : $this
- Merge the validator chain with the one given in parameter
- plugin() : ValidatorInterface
- Retrieve a validator by name
- prependByName() : $this
- Use the plugin manager to prepend a validator by name
- prependValidator() : $this
- Adds a validator to the beginning of the chain
- setPluginManager() : $this
- Set plugin manager instance
Constants
DEFAULT_PRIORITY
Default priority at which validators are added
public
mixed
DEFAULT_PRIORITY
= 1
Properties
$messages
Array of validation failure messages
protected
array<string, string>
$messages
= []
$plugins
protected
ValidatorPluginManager<string|int, ValidatorInterface>|null
$plugins
$validators
Validator chain
protected
PriorityQueue<QueueElement, int>
$validators
Methods
__clone()
Deep clone handling
public
__clone() : mixed
__construct()
Initialize validator chain
public
__construct() : mixed
__invoke()
Invoke chain as command
public
__invoke(mixed $value) : bool
Parameters
- $value : mixed
Return values
bool__sleep()
Prepare validator chain for serialization
public
__sleep() : array<string|int, mixed>
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).
Return values
array<string|int, mixed>addByName()
Proxy to attachByName() to keep BC
public
addByName(string $name[, array<string|int, mixed> $options = [] ][, bool $breakChainOnFailure = false ]) : ValidatorChain
Parameters
- $name : string
- $options : array<string|int, mixed> = []
- $breakChainOnFailure : bool = false
Tags
Return values
ValidatorChainaddValidator()
Proxy to attach() to keep BC
public
addValidator(ValidatorInterface $validator[, bool $breakChainOnFailure = false ][, int $priority = self::DEFAULT_PRIORITY ]) : ValidatorChain
Parameters
- $validator : ValidatorInterface
- $breakChainOnFailure : bool = false
- $priority : int = self::DEFAULT_PRIORITY
Tags
Return values
ValidatorChain —Provides a fluent interface
attach()
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.
public
attach(ValidatorInterface $validator[, bool $breakChainOnFailure = false ][, int $priority = self::DEFAULT_PRIORITY ]) : $this
Parameters
- $validator : ValidatorInterface
- $breakChainOnFailure : bool = false
- $priority : int = self::DEFAULT_PRIORITY
-
Priority at which to enqueue validator; defaults to 1 (higher executes earlier)
Tags
Return values
$thisattachByName()
Use the plugin manager to add a validator by name
public
attachByName(string|ValidatorInterface> $name[, array<string|int, mixed> $options = [] ][, bool $breakChainOnFailure = false ][, int $priority = self::DEFAULT_PRIORITY ]) : $this
Parameters
- $name : string|ValidatorInterface>
- $options : array<string|int, mixed> = []
- $breakChainOnFailure : bool = false
- $priority : int = self::DEFAULT_PRIORITY
Return values
$thiscount()
Return the count of attached validators
public
count() : int
Attributes
Return values
intgetIterator()
public
getIterator() : Traversable<string|int, QueueElement>
Return values
Traversable<string|int, QueueElement>getMessages()
Returns array of validation failure messages
public
getMessages() : array<string, string>
Return values
array<string, string>getPluginManager()
Get plugin manager instance
public
getPluginManager() : ValidatorPluginManager<string|int, ValidatorInterface>
Return values
ValidatorPluginManager<string|int, ValidatorInterface>getValidators()
Get all the validators
public
getValidators() : array<int, QueueElement>
Return values
array<int, QueueElement>isValid()
Returns true if and only if $value passes all validations in the chain
public
isValid(mixed $value[, mixed $context = null ]) : bool
Validators are run in the order in which they were added to the chain (FIFO).
Parameters
- $value : mixed
- $context : mixed = null
-
Extra "context" to provide the validator
Return values
boolmerge()
Merge the validator chain with the one given in parameter
public
merge(ValidatorChain $validatorChain) : $this
Parameters
- $validatorChain : ValidatorChain
Return values
$thisplugin()
Retrieve a validator by name
public
plugin(string|ValidatorInterface> $name[, null|array<string|int, mixed> $options = null ]) : ValidatorInterface
Parameters
- $name : string|ValidatorInterface>
-
Name of validator to return
- $options : null|array<string|int, mixed> = null
-
Options to pass to validator constructor (if not already instantiated)
Tags
Return values
ValidatorInterfaceprependByName()
Use the plugin manager to prepend a validator by name
public
prependByName(string|ValidatorInterface> $name[, array<string|int, mixed> $options = [] ][, bool $breakChainOnFailure = false ]) : $this
Parameters
- $name : string|ValidatorInterface>
- $options : array<string|int, mixed> = []
- $breakChainOnFailure : bool = false
Return values
$thisprependValidator()
Adds a validator to the beginning of the chain
public
prependValidator(ValidatorInterface $validator[, bool $breakChainOnFailure = false ]) : $this
If $breakChainOnFailure is true, then if the validator fails, the next validator in the chain, if one exists, will not be executed.
Parameters
- $validator : ValidatorInterface
- $breakChainOnFailure : bool = false
Return values
$this —Provides a fluent interface
setPluginManager()
Set plugin manager instance
public
setPluginManager(ValidatorPluginManager $plugins) : $this
Parameters
- $plugins : ValidatorPluginManager
-
Plugin manager