ICanBoogie/Errors 2.0.x
  • Namespace
  • Class

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 ICanBoogie\ErrorCollection
# add( string $attribute, ICanBoogie\Error|string|boolean $error_or_format_or_true = true, array $args = [] )

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 ICanBoogie\ErrorCollection
# add_generic( ICanBoogie\Error|string|boolean $error_or_format_or_true = true, array $args = [] )

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 ICanBoogie\Error
# ensure_error_instance( ICanBoogie\Error|string|boolean $error_or_format_or_true, array $args = [] )

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 boolean
# offsetExists( string|null $attribute )

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 ICanBoogie\Error[]
# offsetGet( string|null $attribute )

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 ICanBoogie\ErrorCollection
# clear( )

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( )

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( )

Returns the total number of errors.

Returns the total number of errors.

Inheritdoc

Implementation of

Countable::count()
public
# jsonSerialize( )

Inheritdoc

Implementation of

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

Converts the object into an array.

Converts the object into an array.

Returns

Error[][]

Constants summary

string GENERIC

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__'
ICanBoogie/Errors 2.0.x API documentation generated by ApiGen