imponeer/object-errors

Library that adds a possibility to collect errors for objects

v2.0.7 2024-08-01 00:11 UTC

This package is auto-updated.

Last update: 2024-12-06 04:49:42 UTC


README

License Packagist PHP Packagist

Object Errors

Library that can be used for collecting errors on objects.

Installation

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.

Example

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

}

How to contribute?

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.