ICanBoogie
  • Documentation
  • API Reference
  • Errors 2.0.x
Namespaces
  • ICanBoogie
Classes
  • Error
  • ErrorCollection
  • ErrorCollectionIterator
  • Errors
Interfaces
  • RenderError

Class ErrorCollection

An error collection.

ICanBoogie\ErrorCollection implements ArrayAccess, IteratorAggregate, Countable, JsonSerializable, ICanBoogie\ToArray

Direct known subclasses

ICanBoogie\Errors

Namespace: ICanBoogie
Located at ErrorCollection.php

Methods summary

public add( string $attribute, ICanBoogie\Error|string|boolean $error_or_format_or_true = true, array $args = [] ) : ICanBoogie\ErrorCollection

Add an error associated with an attribute.

Add an error associated with an attribute.

Parameters

$attribute
Attribute name.
$error_or_format_or_true

A ICanBoogie\Error instance or a format to create that instance, or true.

$args

Only used if $error_or_format_or_true is not a ICanBoogie\Error instance or true.

Returns

ICanBoogie\ErrorCollection
$this
public add_generic( ICanBoogie\Error|string|boolean $error_or_format_or_true = true, array $args = [] ) : ICanBoogie\ErrorCollection

Add an error not associated with any attribute.

Add an error not associated with any attribute.

Parameters

$error_or_format_or_true

A ICanBoogie\Error instance or a format to create that instance, or true.

$args

Only used if $error_or_format_or_true is not a ICanBoogie\Error instance or true.

Returns

ICanBoogie\ErrorCollection
$this
protected assert_valid_attribute( string $attribute )

Asserts that an attribute is valid.

Asserts that an attribute is valid.

Parameters

$attribute
protected assert_valid_error( mixed $error_or_format_or_true )

Asserts that the error type is valid.

Asserts that the error type is valid.

Parameters

$error_or_format_or_true
protected ensure_error_instance( ICanBoogie\Error|string|boolean $error_or_format_or_true, array $args = [] ) : ICanBoogie\Error

Ensures a ICanBoogie\Error instance.

Ensures a ICanBoogie\Error instance.

Parameters

$error_or_format_or_true
$args

Returns

ICanBoogie\Error
public offsetSet( string $attribute, ICanBoogie\Error|string|true $error )

Adds an error.

Adds an error.

Parameters

$attribute
$error

See

ICanBoogie\ErrorCollection::add()

Implementation of

ArrayAccess::offsetSet()
public offsetUnset( string|null $attribute )

Clears the errors of an attribute.

Clears the errors of an attribute.

Parameters

$attribute
Attribute name or null for generic.

Implementation of

ArrayAccess::offsetUnset()
public offsetExists( string|null $attribute ) : boolean

Checks if an error is defined for an attribute.

Checks if an error is defined for an attribute.

<?php

use ICanBoogie\ErrorCollection

$errors = new ErrorCollection;
isset($errors['username']);
// false
$errors->add('username');
isset($errors['username']);
// true

Parameters

$attribute
Attribute name or null for generic.

Returns

boolean
true if an error is defined for the specified attribute, false otherwise.

Implementation of

ArrayAccess::offsetExists()
public offsetGet( string|null $attribute ) : ICanBoogie\Error[]

Returns errors associated with an attribute.

Returns errors associated with an attribute.

<?php

use ICanBoogie\ErrorCollection;

$errors = new ErrorCollection;
$errors['password']
// []
$errors->add('password')
// [ Message ]

Parameters

$attribute
Attribute name or null for generic.

Returns

ICanBoogie\Error[]

Implementation of

ArrayAccess::offsetGet()
public clear( void ) : ICanBoogie\ErrorCollection

Clears errors.

Clears errors.

Returns

ICanBoogie\ErrorCollection
$this
public merge( ICanBoogie\ErrorCollection $collection )

Merges with another error collection.

Merges with another error collection.

Parameters

$collection
public getIterator( void )

Inheritdoc

Implementation of

IteratorAggregate::getIterator()
public each( callable $callback )

Iterates through errors using a callback.

Iterates through errors using a callback.

```php <?php

use ICanBoogie\ErrorCollection;

$errors = new ErrorCollection; $errors->add('username', "Funny user name"); $errors->add('password', "Weak password");

$errors->each(function ($error, $attribute, $errors) {

echo "$attribute => $error<br />";

});

Parameters

$callback

Function to execute for each element, taking three arguments:

  • Error $error: The current error.
  • string $attribute: The attribute or self::GENERIC.
  • ErrorCollection $collection: This instance.
public count( void )

Returns the total number of errors.

Returns the total number of errors.

Inheritdoc

Implementation of

Countable::count()
public jsonSerialize( void )

Inheritdoc

Implementation of

JsonSerializable::jsonSerialize()
public to_array( void ) : Error[][]

Converts the object into an array.

Converts the object into an array.

Returns

Error[][]

Constants summary

GENERIC : string

Special identifier used when an error is not associated with a specific attribute.

Special identifier used when an error is not associated with a specific attribute.

'__generic__'
Errors 2.0.x – Check on GitHub – API documentation generated by ApiGen