PHP code example of imponeer / object-errors
1. Go to this page and download the library: Download imponeer/object-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/ */
imponeer / object-errors example snippets
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();
}
}
}