A PHP library for collecting and managing errors associated with objects. Useful for tracking validation or processing errors in a structured way.
Install via Composer:
composer require imponeer/object-errors
Alternatively, you can manually include the files from the src/
directory.
This library allows you to attach an error collection to your objects and manage errors easily.
Below is a simple usage example by directly creating an ErrorsCollection
instance:
use Imponeer\ObjectErrors\ErrorsCollection;
class MyObject {
/**
* @var ErrorsCollection|null
*/
public $errors = null;
public function __construct() {
$this->errors = new ErrorsCollection();
}
public function doSomething() {
// Example logic
if ($failed) {
$this->errors->add("Some error");
}
}
public function render() {
if ($this->errors->isEmpty()) {
return 'Everything fine';
} else {
return $this->errors->getHtml();
}
}
}
You can also use the provided ErrorsTrait
to quickly add error handling to your classes:
use Imponeer\ObjectErrors\ErrorsTrait;
class MyObject {
use ErrorsTrait;
public function doSomething() {
if ($failed) {
$this->setErrors("Some error");
}
}
public function render() {
if ($this->hasError()) {
return $this->getHtmlErrors();
}
return 'Everything fine';
}
}
Below are useful commands for development. Each command should be run from the project root directory.
Run tests using PHPUnit:
composer test
Check code style using PHP_CodeSniffer:
composer phpcs
Automatically fix code style issues:
composer phpcbf
Run static analysis using PHPStan:
composer phpstan
For detailed API documentation, please visit the Object Errors Wiki.
Contributions are welcome! If you want to add new features or fix bugs, please fork the repository, make your changes, and submit a pull request.
If you find any bugs or have questions, please use the issues tab to report them or ask questions.