Total Complexity | 13 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
5 | trait Helper |
||
6 | { |
||
7 | protected static Validator $instance; |
||
8 | protected array $data = []; |
||
9 | protected array $validators = []; |
||
10 | protected string $model = ''; |
||
11 | protected array $required = []; |
||
12 | protected array $errors = []; |
||
13 | protected static array $err = []; |
||
14 | |||
15 | |||
16 | protected static function array($value): Array |
||
17 | { |
||
18 | return (is_array($value)) ? $value : [ $value ]; |
||
19 | } |
||
20 | |||
21 | protected static function getInstance(?string $lang = null): Validator |
||
22 | { |
||
23 | self::$instance = (isset(self::$instance)) ? self::$instance : new Validator($lang); |
||
24 | return self::$instance; |
||
25 | } |
||
26 | |||
27 | protected function error(array $error): void |
||
28 | { |
||
29 | $this->errors[] = $error; |
||
30 | } |
||
31 | |||
32 | protected function data($field = null, ?array $values = null) |
||
33 | { |
||
34 | if(null !== $values){ |
||
35 | $this->data[$field] = $values; |
||
36 | } |
||
37 | if(null !== $field){ |
||
38 | return $this->data[$field]; |
||
39 | } |
||
40 | return $this->data; |
||
41 | } |
||
42 | |||
43 | protected function validator(string $model, ?object $callback = null) |
||
44 | { |
||
45 | if(null !== $callback){ |
||
46 | $this->validators[$model] = $callback; |
||
47 | } |
||
48 | return $this->validators[$model]; |
||
49 | } |
||
50 | |||
51 | protected function model(?string $model = null): string |
||
52 | { |
||
53 | if(null !== $model){ |
||
54 | $this->model = $model; |
||
55 | } |
||
56 | return $this->model; |
||
57 | } |
||
58 | |||
59 | protected function required(): array |
||
62 | } |
||
63 | |||
64 | } |
||
65 |