HumHub Documentation (unofficial)

ValidatorChain
in package
implements Countable, IteratorAggregate, ValidatorInterface

Tags
psalm-type

QueueElement = array{instance: ValidatorInterface, breakChainOnFailure: bool}

implements

IteratorAggregate<array-key, QueueElement>

final

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 = []

Methods

__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
deprecated

Please use attachByName()

Return values
ValidatorChain

addValidator()

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
deprecated

Please use attach()

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
throws
InvalidArgumentException
Return values
$this

attachByName()

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
$this

getIterator()

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>

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
bool

plugin()

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
template

T of ValidatorInterface

psalm-param

string|class-string<T> $name

psalm-return

ValidatorInterface

Return values
ValidatorInterface

prependByName()

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
$this

prependValidator()

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


        
On this page

Search results