1 | <?php |
||
13 | class Rule implements \PluginSimpleValidate\Contracts\Rule |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $validationMethod; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $langKey; |
||
24 | |||
25 | /** |
||
26 | * @var bool |
||
27 | */ |
||
28 | private $status; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $error; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | private $args; |
||
39 | |||
40 | /** |
||
41 | * Rule constructor. |
||
42 | * @param string $validationMethod |
||
43 | * @param string $langKey |
||
44 | * @param array $args |
||
45 | */ |
||
46 | 9 | public function __construct(string $validationMethod, string $langKey, $args = []) |
|
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | 9 | public function getValidationMethod(): string |
|
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 9 | public function getLangKey(): string |
|
70 | |||
71 | /** |
||
72 | * @return bool |
||
73 | */ |
||
74 | public function getStatus(): bool |
||
78 | |||
79 | /** |
||
80 | * @param Language $language |
||
81 | * @param $value |
||
82 | * @return bool |
||
83 | */ |
||
84 | 9 | public function isValid(Language $language, $value) : bool |
|
85 | { |
||
86 | 9 | if (!call_user_func_array( |
|
87 | 9 | '\\PluginSimpleValidate\\helper\\Validate\\' . $this->getValidationMethod(), |
|
88 | [ |
||
89 | 9 | $value, |
|
90 | 9 | $this->args |
|
91 | ] |
||
92 | )) { |
||
93 | 9 | $this->status = false; |
|
94 | |||
95 | 9 | $this->error = vsprintf( |
|
96 | 9 | $language->getTranslation( |
|
97 | 9 | $this->getLangKey() |
|
98 | ), |
||
99 | 9 | $this->args |
|
100 | ); |
||
101 | |||
102 | } else { |
||
103 | 1 | $this->status = true; |
|
104 | } |
||
105 | |||
106 | 9 | return $this->status; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | 9 | public function getError(): string |
|
116 | } |