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
Interfaces, Classes, Traits and Enums
- RecursiveIterator
- SeekableIterator
- ArrayAccess
- Countable
Table of Contents
- INDENTATION = ' '
- The prefix used for indenting nested error messages.
- $errors : mixed
- $form : mixed
- __construct() : mixed
- __toString() : string
- Returns all iterated error messages as string.
- count() : int
- Returns the number of elements in the iterator.
- current() : FormError|self
- Returns the current element of the iterator.
- findByCodes() : static
- Creates iterator for errors with specific codes.
- getChildren() : self
- Alias of {@link current()}.
- 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() : mixed
- Advances the iterator to the next position.
- offsetExists() : bool
- Returns whether a position exists in the iterator.
- offsetGet() : FormError|FormErrorIterator
- Returns the element at a position in the iterator.
- offsetSet() : void
- Unsupported method.
- offsetUnset() : void
- Unsupported method.
- rewind() : mixed
- 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
mixed
$errors
$form
private
mixed
$form
Methods
__construct()
public
__construct(FormInterface $form, array<string|int, FormError>|array<string|int, self> $errors) : mixed
Parameters
- $form : FormInterface
- $errors : array<string|int, FormError>|array<string|int, self>
-
An array of form errors and instances of FormErrorIterator
Tags
Return values
mixed —__toString()
Returns all iterated error messages as string.
public
__toString() : string
Return values
string —The iterated error messages
count()
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
int —The number of iterated elements
current()
Returns the current element of the iterator.
public
current() : FormError|self
Return values
FormError|self —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
static —new instance which contains only specific errors
getChildren()
Alias of {@link current()}.
public
getChildren() : self
Return values
self —getForm()
Returns the iterated form.
public
getForm() : FormInterface
Return values
FormInterface —The form whose errors are iterated by this object
hasChildren()
Returns whether the current element of the iterator can be recursed into.
public
hasChildren() : bool
Return values
bool —Whether the current element is an instance of this class
key()
Returns the current position of the iterator.
public
key() : int
Return values
int —The 0-indexed position
next()
Advances the iterator to the next position.
public
next() : mixed
Return values
mixed —offsetExists()
Returns whether a position exists in the iterator.
public
offsetExists(int $position) : bool
Parameters
- $position : int
-
The position
Return values
bool —Whether that position exists
offsetGet()
Returns the element at a position in the iterator.
public
offsetGet(int $position) : FormError|FormErrorIterator
Parameters
- $position : int
-
The position
Tags
Return values
FormError|FormErrorIterator —The element at the given position
offsetSet()
Unsupported method.
public
offsetSet(mixed $position, mixed $value) : void
Parameters
- $position : mixed
- $value : mixed
Tags
Return values
void —offsetUnset()
Unsupported method.
public
offsetUnset(mixed $position) : void
Parameters
- $position : mixed
Tags
Return values
void —rewind()
Sets the iterator's position to the beginning.
public
rewind() : mixed
This method detects if errors have been added to the form since the construction of the iterator.
Return values
mixed —seek()
Sets the position of the iterator.
public
seek(int $position) : void
Parameters
- $position : int
-
The new position
Tags
Return values
void —valid()
Returns whether the iterator's position is valid.
public
valid() : bool
Return values
bool —Whether the iterator is valid
indent()
Utility function for indenting multi-line strings.
private
static indent(string $string) : string
Parameters
- $string : string