FormErrorIterator
in package
implements
RecursiveIterator, SeekableIterator, ArrayAccess, Countable
Iterates over the errors of a form.
This class supports recursive iteration. In order to iterate recursively, pass a structure of and objects to the $errors constructor argument.
You can also wrap the iterator into a to flatten the recursive structure into a flat list of errors.
Tags
Table of Contents
Interfaces
- RecursiveIterator
- SeekableIterator
- ArrayAccess
- Countable
Constants
- INDENTATION = ' '
- The prefix used for indenting nested error messages.
Properties
Methods
- __construct() : mixed
- __toString() : string
- Returns all iterated error messages as string.
- count() : int
- Returns the number of elements in the iterator.
- current() : T
- Returns the current element of the iterator.
- findByCodes() : static
- Creates iterator for errors with specific codes.
- getChildren() : self
- getForm() : FormInterface
- Returns the iterated form.
- hasChildren() : bool
- Returns whether the current element of the iterator can be recursed into.
- key() : int
- Returns the current position of the iterator.
- next() : void
- Advances the iterator to the next position.
- offsetExists() : bool
- Returns whether a position exists in the iterator.
- offsetGet() : T
- Returns the element at a position in the iterator.
- offsetSet() : void
- Unsupported method.
- offsetUnset() : void
- Unsupported method.
- rewind() : void
- Sets the iterator's position to the beginning.
- seek() : void
- Sets the position of the iterator.
- valid() : bool
- Returns whether the iterator's position is valid.
- indent() : string
- Utility function for indenting multi-line strings.
Constants
INDENTATION
The prefix used for indenting nested error messages.
public
mixed
INDENTATION
= ' '
Properties
$errors
private
array<int, T>
$errors
$form
private
mixed
$form
Methods
__construct()
public
__construct(FormInterface $form, array<int, T> $errors) : mixed
Parameters
- $form : FormInterface
- $errors : array<int, T>
Tags
__toString()
Returns all iterated error messages as string.
public
__toString() : string
Return values
stringcount()
Returns the number of elements in the iterator.
public
count() : int
Note that this is not the total number of errors, if the constructor parameter $deep was set to true! In that case, you should wrap the iterator into a with the standard mode and count the result.
$iterator = new \RecursiveIteratorIterator($form->getErrors(true));
$count = count(iterator_to_array($iterator));
Alternatively, set the constructor argument $flatten to true as well.
$count = count($form->getErrors(true, true));
Return values
intcurrent()
Returns the current element of the iterator.
public
current() : T
Return values
T —An error or an iterator containing nested errors
findByCodes()
Creates iterator for errors with specific codes.
public
findByCodes(string|array<string|int, string> $codes) : static
Parameters
- $codes : string|array<string|int, string>
-
The codes to find
Return values
staticgetChildren()
public
getChildren() : self
Return values
selfgetForm()
Returns the iterated form.
public
getForm() : FormInterface
Return values
FormInterfacehasChildren()
Returns whether the current element of the iterator can be recursed into.
public
hasChildren() : bool
Return values
boolkey()
Returns the current position of the iterator.
public
key() : int
Return values
intnext()
Advances the iterator to the next position.
public
next() : void
offsetExists()
Returns whether a position exists in the iterator.
public
offsetExists(int $position) : bool
Parameters
- $position : int
-
The position
Return values
booloffsetGet()
Returns the element at a position in the iterator.
public
offsetGet(int $position) : T
Parameters
- $position : int
-
The position
Tags
Return values
ToffsetSet()
Unsupported method.
public
offsetSet(mixed $position, mixed $value) : void
Parameters
- $position : mixed
- $value : mixed
Tags
offsetUnset()
Unsupported method.
public
offsetUnset(mixed $position) : void
Parameters
- $position : mixed
Tags
rewind()
Sets the iterator's position to the beginning.
public
rewind() : void
This method detects if errors have been added to the form since the construction of the iterator.
seek()
Sets the position of the iterator.
public
seek(int $position) : void
Parameters
- $position : int
Tags
valid()
Returns whether the iterator's position is valid.
public
valid() : bool
Return values
boolindent()
Utility function for indenting multi-line strings.
private
static indent(string $string) : string
Parameters
- $string : string