@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | //----------------------------------------------------------- INITIALISATION |
16 | 16 | public function __construct($settings) |
17 | 17 | { |
18 | - if(!isset($settings['route_home'])) |
|
19 | - throw new RouterException('ROUTE_HOME_UNDEFINED'); |
|
18 | + if(!isset($settings['route_home'])) { |
|
19 | + throw new RouterException('ROUTE_HOME_UNDEFINED'); |
|
20 | + } |
|
20 | 21 | |
21 | 22 | parent::__construct(); |
22 | 23 | |
@@ -42,13 +43,15 @@ discard block |
||
42 | 43 | { |
43 | 44 | $this->match = parent::match($requestUrl, $requestMethod); |
44 | 45 | |
45 | - if($this->match === false) |
|
46 | - throw new RouterException('ROUTE_MATCH_FALSE'); |
|
46 | + if($this->match === false) { |
|
47 | + throw new RouterException('ROUTE_MATCH_FALSE'); |
|
48 | + } |
|
47 | 49 | |
48 | 50 | $res = explode('::', self::target()); |
49 | 51 | |
50 | - if($res === false || !isset($res[1]) || isset($ret[2])) |
|
51 | - throw new RouterException('INVALID_TARGET'); |
|
52 | + if($res === false || !isset($res[1]) || isset($ret[2])) { |
|
53 | + throw new RouterException('INVALID_TARGET'); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // if($this->match['name'] === 'akadok_controller_method') |
54 | 57 | // $res = [ucfirst(self::params('controller')).'Controller', ucfirst(self::params('method'))]; |
@@ -58,12 +61,14 @@ discard block |
||
58 | 61 | $target_method = $res[1]; |
59 | 62 | $found = false; |
60 | 63 | |
61 | - foreach($this->controller_namespaces as $controller_ns) |
|
62 | - if($found = class_exists($controller_class_name = "$controller_ns$target_controller")) |
|
64 | + foreach($this->controller_namespaces as $controller_ns) { |
|
65 | + if($found = class_exists($controller_class_name = "$controller_ns$target_controller")) |
|
63 | 66 | break; |
67 | + } |
|
64 | 68 | |
65 | - if($found === false) |
|
66 | - throw new RouterException('INVALID_CONTROLLER_NAME'); |
|
69 | + if($found === false) { |
|
70 | + throw new RouterException('INVALID_CONTROLLER_NAME'); |
|
71 | + } |
|
67 | 72 | |
68 | 73 | $this->match['target_controller'] = $controller_class_name; |
69 | 74 | $this->match['target_method'] = $target_method; |
@@ -85,16 +90,19 @@ discard block |
||
85 | 90 | { |
86 | 91 | |
87 | 92 | // $key is null, returns $dat_ass or empty array |
88 | - if(is_null($key)) |
|
89 | - return $dat_ass ?? []; |
|
93 | + if(is_null($key)) { |
|
94 | + return $dat_ass ?? []; |
|
95 | + } |
|
90 | 96 | |
91 | 97 | // $dat_ass[$key] not set, returns null |
92 | - if(!isset($dat_ass[$key])) |
|
93 | - return null; |
|
98 | + if(!isset($dat_ass[$key])) { |
|
99 | + return null; |
|
100 | + } |
|
94 | 101 | |
95 | 102 | // $dat_ass[$key] is a string, returns decoded value |
96 | - if(is_string($dat_ass[$key])) |
|
97 | - return urldecode($dat_ass[$key]); |
|
103 | + if(is_string($dat_ass[$key])) { |
|
104 | + return urldecode($dat_ass[$key]); |
|
105 | + } |
|
98 | 106 | |
99 | 107 | // $dat_ass[$key] is not a string, return match[$key] |
100 | 108 | return $dat_ass[$key]; |
@@ -144,7 +152,7 @@ discard block |
||
144 | 152 | { |
145 | 153 | try{ |
146 | 154 | $url = $this->generate($route, $route_params); |
147 | - }catch(\Exception $e){ |
|
155 | + } catch(\Exception $e){ |
|
148 | 156 | $url = $this->prehop(self::ROUTE_HOME_NAME); |
149 | 157 | } |
150 | 158 | |
@@ -167,12 +175,13 @@ discard block |
||
167 | 175 | { |
168 | 176 | $url = null; |
169 | 177 | |
170 | - if(is_null($route)) |
|
171 | - $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params); |
|
172 | - elseif(is_string($route) && $this->route_exists($route)) |
|
173 | - $url = $this->prehop($route, $route_params); |
|
174 | - else |
|
175 | - $url = $route; |
|
178 | + if(is_null($route)) { |
|
179 | + $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params); |
|
180 | + } elseif(is_string($route) && $this->route_exists($route)) { |
|
181 | + $url = $this->prehop($route, $route_params); |
|
182 | + } else { |
|
183 | + $url = $route; |
|
184 | + } |
|
176 | 185 | |
177 | 186 | $this->hop_url($url); |
178 | 187 | } |
@@ -180,8 +189,9 @@ discard block |
||
180 | 189 | // hops back to previous page (referer()), or home if no referer |
181 | 190 | public function hop_back() |
182 | 191 | { |
183 | - if(!is_null($back = $this->referer())) |
|
184 | - $this->hop_url($back); |
|
192 | + if(!is_null($back = $this->referer())) { |
|
193 | + $this->hop_url($back); |
|
194 | + } |
|
185 | 195 | |
186 | 196 | $this->hop(); |
187 | 197 | } |
@@ -198,16 +208,18 @@ discard block |
||
198 | 208 | // returns null if same as current URL (prevents endless redirection loop) |
199 | 209 | public function referer() |
200 | 210 | { |
201 | - if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) |
|
202 | - return $_SERVER['HTTP_REFERER']; |
|
211 | + if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) { |
|
212 | + return $_SERVER['HTTP_REFERER']; |
|
213 | + } |
|
203 | 214 | |
204 | 215 | return null; |
205 | 216 | } |
206 | 217 | |
207 | 218 | public function send_file($file_path) |
208 | 219 | { |
209 | - if(!file_exists($file_path)) |
|
210 | - throw new RouterException('SENDING_NON_EXISTING_FILE'); |
|
220 | + if(!file_exists($file_path)) { |
|
221 | + throw new RouterException('SENDING_NON_EXISTING_FILE'); |
|
222 | + } |
|
211 | 223 | |
212 | 224 | $file_name = basename($file_path); |
213 | 225 |