| Total Complexity | 6 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | class Factory implements FactoryInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Cached instance of the validation factory. |
||
| 14 | * |
||
| 15 | * @var static |
||
| 16 | */ |
||
| 17 | private static $instance; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * All available validation rules. |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | protected $available = []; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Validation service factory constructor. |
||
| 28 | */ |
||
| 29 | public function __construct() |
||
| 30 | { |
||
| 31 | $this->extend(require __DIR__ . '/../config/aliases.php'); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Returns singleton instance of the validation factory. |
||
| 36 | * It's supposed to use only in container unaware environments. |
||
| 37 | * |
||
| 38 | * @return static |
||
| 39 | */ |
||
| 40 | public static function getInstance() |
||
| 41 | { |
||
| 42 | if (static::$instance === null) { |
||
|
|
|||
| 43 | return static::$instance = new static; |
||
| 44 | } |
||
| 45 | |||
| 46 | return static::$instance; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Creates new validator instance. |
||
| 51 | * |
||
| 52 | * @param array $data |
||
| 53 | * @param array $rules |
||
| 54 | * @param array $messages |
||
| 55 | * |
||
| 56 | * @return Validator |
||
| 57 | */ |
||
| 58 | public function make(array $data, array $rules, array $messages = []) |
||
| 59 | { |
||
| 60 | return (new Validator($data, $rules, $messages))->extend($this->available); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Extends available rules with new ones. |
||
| 65 | * |
||
| 66 | * @param array $rules |
||
| 67 | * |
||
| 68 | * @return $this |
||
| 69 | */ |
||
| 70 | public function extend(array $rules) |
||
| 71 | { |
||
| 72 | $this->available = array_merge($this->available, $rules); |
||
| 73 | |||
| 74 | return $this; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Returns all available validation rules. |
||
| 79 | * |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | public function getAvailable() |
||
| 85 | } |
||
| 86 | } |
||
| 87 |