Library that can be used for collecting errors on objects.
To install and use this package, we recommend to use Composer:
composer require imponeer/object-errors
Otherwise you need to include manualy files from src/
directory.
use Imponeer/ObjectErrors/ErrorsCollection;
class Object {
/**
* Errors variable
*
* @var null|ErrorsCollection
*/
public $errors = null;
/**
* Constructor (binds new instance of ErrorsCollection to $errors var)
*/
public function __constructor() {
$this->errors = new ErrorsCollection();
}
/**
* This method do something
*/
public function doSomething() {
// here we should do something
if ($failed) {
$this->errors->add("Some error");
}
}
/**
* Renders object content
*
* @return string
*/
public function render() {
if ($this->errors->isEmpty()) {
return 'Everything fine';
} else {
return $this->errors->getHTML();
}
}
}
If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try interactive GitHub tutorial.
If you found any bug or have some questions, use issues tab and write there your questions.