PHP code example of icanboogie / errors
1. Go to this page and download the library: Download icanboogie/errors library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
icanboogie / errors example snippets
use ICanBoogie\ErrorCollection;
$errors = new ErrorCollection;
var_dump($errors['password']);
// null
$errors->add('password');
var_dump($errors['password']);
// [ Error{ format: '', params: [] } ]
$errors->add('password', 'Invalid password: {value}', [ 'value' => "123" ]);
var_dump($errors['password']);
// 'Invalid password: 123'
$errors['password'] = 'Ugly password';
var_dump($errors['password']);
// array('Invalid password', 'Ugly password')
$errors->add_generic('General error');
count($errors);
// 3
$errors->each(function($name, $message) {
echo "$name: $message\n";
});
// General error
// password: Invalid password
// password: Ugly password