ICanBoogie/Errors master
  • Namespace
  • Class

Namespaces

  • ICanBoogie

Classes

  • Errors

Class Errors

An error collector.

ICanBoogie\Errors implements ArrayAccess, Countable, Iterator
Namespace: ICanBoogie
Located at Errors.php

Methods summary

public boolean
# offsetExists( $attribute )

Checks if an error is defined for an attribute.

Checks if an error is defined for an attribute.

Example:

$e = new Errors();
$e['username'] = 'Funny username';
var_dump(isset($e['username']);
#=> true
var_dump(isset($e['password']);
#=> false

Returns

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

Implementation of

ArrayAccess::offsetExists()
public string|array|null
# offsetGet( string|null $attribute )

Returns error messages.

Returns error messages.

Example:

$e = new Errors();
var_dump($e['password']);
#=> null
$e['password'] = 'Invalid password';
var_dump($e['password']);
#=> 'Invalid password'
$e['password'] = 'Ugly password';
var_dump($e['password']);
#=> array('Invalid password', 'Ugly password')

Parameters

$attribute
The attribute that caused the error, or null if the error is global.

Returns

string|array|null

Return the global error messages or the error messages attached to an attribute. If there is only one message a string is returned, otherwise an array with all the messages is returned. null is returned if there is no message defined.

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( string|null $attribute, string $message )

Adds an error message.

Adds an error message.

Example:

$e = new Errors();
$e['password'] = 'Invalid password';
$e[] = 'Requires authentication';

Parameters

$attribute

If null, the message is considered as a general error message instead of an attribute message.

$message
The error message.

Implementation of

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

Removes error messages.

Removes error messages.

Parameters

$attribute

If null, general message are removed, otherwise the message attached to the attribute are removed.

Implementation of

ArrayAccess::offsetUnset()
public
# count( )

Returns the number of errors defined.

Returns the number of errors defined.

Example:

$e = new Errors();
$e['username'] = 'Funny user name';
$e['password'] = 'Weak password';
$e['password'] = 'should have at least one digit';
count($e);
#=> 3

Implementation of

Countable::count()
public
# current( )

Implementation of

Iterator::current()
public
# next( )

Implementation of

Iterator::next()
public
# key( )

Implementation of

Iterator::key()
public
# valid( )

Implementation of

Iterator::valid()
public
# rewind( )

Implementation of

Iterator::rewind()
public
# each( mixed $callback )

Iterates through errors using the specified callback.

Iterates through errors using the specified callback.

Example:

$e = new Errors();
$e['username'] = 'Funny user name';
$e['password'] = 'Weak password';

$e->each(function($attribute, $message) {

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

});

Parameters

$callback
public
# clear( )

Clears the errors.

Clears the errors.

public mixed
# format( string $pattern, array $args = array(), array $options = array() )

Formats the given string by replacing placeholders with the values provided.

Formats the given string by replacing placeholders with the values provided.

Parameters

$pattern
The format pattern.
$args
An array of replacements for the placeholders.
$options
Options for the formatter.

Returns

mixed
A string or a stringyfiable object.

See

\ICanBoogie\I18n\FormattedString
\ICanBoogie\FormattedString
\ICanBoogie\format
public string
# add( string $id, string $pattern, array $args = array(), array $options = array() )

Formats and add an error message.

Formats and add an error message.

Parameters

$id
$pattern
The format pattern.
$args
An array of replacements for the placeholders.
$options
Options for the formatter.

Returns

string
The formatted message.

Properties summary

public static $message_constructor
#
protected array $errors
# array(null => array())
ICanBoogie/Errors master API documentation generated by ApiGen