| 1 |
<?php |
| 2 |
/** |
| 3 |
* Checker abstract |
| 4 |
* |
| 5 |
* @package micropackage/requirements |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Micropackage\Requirements\Abstracts; |
| 9 |
|
| 10 |
use Micropackage\Requirements\Interfaces; |
| 11 |
|
| 12 |
/** |
| 13 |
* Checker abstract |
| 14 |
*/ |
| 15 |
abstract class Checker implements Interfaces\Checkable { |
| 16 |
|
| 17 |
/** |
| 18 |
* Checker name |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
protected $name = ''; |
| 23 |
|
| 24 |
/** |
| 25 |
* Error messages |
| 26 |
* |
| 27 |
* @var array |
| 28 |
*/ |
| 29 |
protected $errors = []; |
| 30 |
|
| 31 |
/** |
| 32 |
* Checks if the requirement is met |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
* @param mixed $value Value to check against. |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
abstract public function check( $value ); |
| 39 |
|
| 40 |
/** |
| 41 |
* Gets checker name |
| 42 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
* @return string |
| 45 |
*/ |
| 46 |
public function get_name() { |
| 47 |
return $this->name; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Adds error message |
| 52 |
* |
| 53 |
* @since 1.0.0 |
| 54 |
* @param string $message Error message. |
| 55 |
* @return $this |
| 56 |
*/ |
| 57 |
public function add_error( $message ) { |
| 58 |
$this->errors[] = $message; |
| 59 |
return $this; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Gets all errors |
| 64 |
* |
| 65 |
* @since 1.0.0 |
| 66 |
* @return array |
| 67 |
*/ |
| 68 |
public function get_errors() { |
| 69 |
return $this->errors; |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|