@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use Psr\Http\Server\RequestHandlerInterface; |
7 | 7 | use Psr\Http\Message\ResponseInterface; |
8 | 8 | |
9 | -trait MiddlewareTrait{ |
|
9 | +trait MiddlewareTrait { |
|
10 | 10 | |
11 | 11 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
12 | 12 | { |
@@ -20,17 +20,17 @@ discard block |
||
20 | 20 | |
21 | 21 | private function requestData(ServerRequestInterface $request): array |
22 | 22 | { |
23 | - return ($request->getAttribute('validator') !== null && isset($request->getAttribute('validator')['data'])) ? $request->getAttribute('validator')['data'] : $_REQUEST; |
|
23 | + return ($request->getAttribute('validator')!==null && isset($request->getAttribute('validator')['data'])) ? $request->getAttribute('validator')['data'] : $_REQUEST; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | private function requestNamespace(ServerRequestInterface $request): string |
27 | 27 | { |
28 | - return ($request->getAttribute('validator') !== null && isset($request->getAttribute('validator')['namespace'])) ? $request->getAttribute('validator')['namespace'] : ''; |
|
28 | + return ($request->getAttribute('validator')!==null && isset($request->getAttribute('validator')['namespace'])) ? $request->getAttribute('validator')['namespace'] : ''; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | private function requestLang(ServerRequestInterface $request): string |
32 | 32 | { |
33 | - return ($request->getAttribute('validator') !== null && isset($request->getAttribute('validator')['lang'])) ? $request->getAttribute('validator')['lang'] : 'en'; |
|
33 | + return ($request->getAttribute('validator')!==null && isset($request->getAttribute('validator')['lang'])) ? $request->getAttribute('validator')['lang'] : 'en'; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | } |
37 | 37 | \ No newline at end of file |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct(?string $lang = null) |
16 | 16 | { |
17 | - $lang = (null !== $lang) ? $lang : 'en'; |
|
18 | - require __DIR__.DIRECTORY_SEPARATOR.'languages'. DIRECTORY_SEPARATOR . $lang .'.php'; |
|
17 | + $lang = (null!==$lang) ? $lang : 'en'; |
|
18 | + require __DIR__.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.$lang.'.php'; |
|
19 | 19 | self::$err = (isset($VALIDATOR_LANG)) ? $VALIDATOR_LANG : []; |
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function lang(string $lang): Validator |
23 | 23 | { |
24 | 24 | unset($VALIDATOR_LANG); |
25 | - require __DIR__.DIRECTORY_SEPARATOR.'languages'. DIRECTORY_SEPARATOR . $lang .'.php'; |
|
25 | + require __DIR__.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.$lang.'.php'; |
|
26 | 26 | self::$err = (isset($VALIDATOR_LANG)) ? $VALIDATOR_LANG : []; |
27 | 27 | return self::getInstance($lang); |
28 | 28 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | private static function getClass(string $class) |
44 | 44 | { |
45 | - if(!class_exists($class)){ |
|
45 | + if (!class_exists($class)) { |
|
46 | 46 | throw new \RuntimeException(self::$err['nFormID']); |
47 | 47 | } |
48 | 48 | |
@@ -53,21 +53,21 @@ discard block |
||
53 | 53 | |
54 | 54 | private function existRole($getRules) |
55 | 55 | { |
56 | - if(empty(self::getInstance()->validator($getRules)->getRules(self::getInstance()->data['_ROLE']))){ |
|
56 | + if (empty(self::getInstance()->validator($getRules)->getRules(self::getInstance()->data['_ROLE']))) { |
|
57 | 57 | throw new \RuntimeException(self::$err['nFoundForm']); |
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | public function checkDatas(array $data): void |
62 | 62 | { |
63 | - if(!isset($data['_PROVIDER']) || !isset($data['_ROLE'])){ |
|
63 | + if (!isset($data['_PROVIDER']) || !isset($data['_ROLE'])) { |
|
64 | 64 | throw new \RuntimeException(self::$err['issetData']); |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | public static function execute(array $data): bool |
69 | 69 | { |
70 | - try{ |
|
70 | + try { |
|
71 | 71 | self::getInstance()->checkDatas($data); |
72 | 72 | |
73 | 73 | self::getInstance()->data = $data; |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | |
79 | 79 | self::getInstance()->existRole(self::getInstance()->model); |
80 | 80 | |
81 | - foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules($data['_ROLE'])) as $key => $value) { |
|
82 | - if(@$value['required'] === true){ |
|
81 | + foreach ((self::getInstance()->validator(self::getInstance()->model)->getRules($data['_ROLE'])) as $key => $value) { |
|
82 | + if (@$value['required']===true) { |
|
83 | 83 | self::getInstance()->required[$key] = $value; |
84 | 84 | } |
85 | 85 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | self::getInstance()->validate(); |
90 | 90 | self::getInstance()->requireds(); |
91 | - }catch(\Exception $er){ |
|
91 | + }catch (\Exception $er) { |
|
92 | 92 | self::getInstance()->errors[] = ['form' => $er->getMessage()]; |
93 | 93 | } |
94 | 94 | |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | |
98 | 98 | public static function errors(): bool |
99 | 99 | { |
100 | - return (count(self::getInstance()->errors) === 0); |
|
100 | + return (count(self::getInstance()->errors)===0); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | public function validate(): void |
104 | 104 | { |
105 | - foreach ( (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
|
105 | + foreach ((self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) as $key => $value) { |
|
106 | 106 | |
107 | 107 | foreach (self::getInstance()->data as $keyy => $valuee) { |
108 | 108 | |
109 | 109 | self::getInstance()->checkExpected($keyy); |
110 | 110 | |
111 | - if($keyy!==$key){ |
|
111 | + if ($keyy!==$key) { |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $function = strtolower($subkey); |
120 | 120 | |
121 | - self::getInstance()->hasMethod($function)->$function($keyy, $subvalue, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) ); |
|
121 | + self::getInstance()->hasMethod($function)->$function($keyy, $subvalue, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE']))); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | } |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | |
128 | 128 | private function checkExpected(string $keyy): void |
129 | 129 | { |
130 | - if(!array_key_exists($keyy, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE'])) ) && !in_array($keyy, self::getInstance()->defaultData)){ |
|
131 | - throw new \RuntimeException($keyy . self::$err['nExpected']); |
|
130 | + if (!array_key_exists($keyy, (self::getInstance()->validator(self::getInstance()->model)->getRules(self::getInstance()->data['_ROLE']))) && !in_array($keyy, self::getInstance()->defaultData)) { |
|
131 | + throw new \RuntimeException($keyy.self::$err['nExpected']); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | |
140 | 140 | public function hasMethod($method): Validator |
141 | 141 | { |
142 | - if(!method_exists(static::class, $method)){ |
|
143 | - throw new \RuntimeException($method . self::$err['nMethod']); |
|
142 | + if (!method_exists(static::class, $method)) { |
|
143 | + throw new \RuntimeException($method.self::$err['nMethod']); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return $this; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | self::getInstance()->existRole(self::getInstance()->model()); |
163 | 163 | |
164 | - foreach ( self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
164 | + foreach (self::getInstance()->validator(self::getInstance()->model())->getRules($request['_ROLE']) as $field => $r) { |
|
165 | 165 | $r = self::getInstance()->replaceRegex($r); |
166 | 166 | $response .= ("'$field':".json_encode(array_reverse($r))).','; |
167 | 167 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | private function replaceRegex(array $getRules): array |
173 | 173 | { |
174 | - if(array_key_exists('regex', $getRules)){ |
|
174 | + if (array_key_exists('regex', $getRules)) { |
|
175 | 175 | $getRules['regex'] = substr($getRules['regex'], 1, -2); |
176 | 176 | } |
177 | 177 |