Documentation

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
author

Bernhard Schussek bschussek@gmail.com

template

T of FormError|FormErrorIterator

implements

\ArrayAccess<int, T>

implements

\RecursiveIterator<int, T>

implements

\SeekableIterator<int, T>

Table of Contents

Interfaces

RecursiveIterator
SeekableIterator
ArrayAccess
Countable

Constants

INDENTATION  = ' '
The prefix used for indenting nested error messages.

Properties

$errors  : array<int, T>
$form  : mixed

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

Methods

__toString()

Returns all iterated error messages as string.

public __toString() : string
Return values
string

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

current()

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
static

hasChildren()

Returns whether the current element of the iterator can be recursed into.

public hasChildren() : bool
Return values
bool

key()

Returns the current position of the iterator.

public key() : int
Return values
int

offsetExists()

Returns whether a position exists in the iterator.

public offsetExists(int $position) : bool
Parameters
$position : int

The position

Return values
bool

offsetGet()

Returns the element at a position in the iterator.

public offsetGet(int $position) : T
Parameters
$position : int

The position

Tags
throws
OutOfBoundsException

If the given position does not exist

Return values
T

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.

valid()

Returns whether the iterator's position is valid.

public valid() : bool
Return values
bool

indent()

Utility function for indenting multi-line strings.

private static indent(string $string) : string
Parameters
$string : string
Return values
string

        
On this page

Search results