@@ -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 | |
@@ -41,25 +42,29 @@ discard block |
||
41 | 42 | { |
42 | 43 | $this->match = parent::match($requestUrl, $requestMethod); |
43 | 44 | |
44 | - if($this->match === false) |
|
45 | - throw new RouterException('ROUTE_MATCH_FALSE'); |
|
45 | + if($this->match === false) { |
|
46 | + throw new RouterException('ROUTE_MATCH_FALSE'); |
|
47 | + } |
|
46 | 48 | |
47 | 49 | $res = explode('::', $this->target()); |
48 | 50 | |
49 | - if($res === false || !isset($res[1]) || isset($res[2])) |
|
50 | - throw new RouterException('INVALID_TARGET'); |
|
51 | + if($res === false || !isset($res[1]) || isset($res[2])) { |
|
52 | + throw new RouterException('INVALID_TARGET'); |
|
53 | + } |
|
51 | 54 | |
52 | 55 | $target_controller = $res[0]; |
53 | 56 | $target_method = $res[1]; |
54 | 57 | $found = false; |
55 | 58 | |
56 | 59 | $controller_class_name = null; |
57 | - foreach($this->controller_namespaces as $controller_ns) |
|
58 | - if($found = class_exists($controller_class_name = "$controller_ns$target_controller")) |
|
60 | + foreach($this->controller_namespaces as $controller_ns) { |
|
61 | + if($found = class_exists($controller_class_name = "$controller_ns$target_controller")) |
|
59 | 62 | break; |
63 | + } |
|
60 | 64 | |
61 | - if($found === false) |
|
62 | - throw new RouterException('INVALID_CONTROLLER_NAME'); |
|
65 | + if($found === false) { |
|
66 | + throw new RouterException('INVALID_CONTROLLER_NAME'); |
|
67 | + } |
|
63 | 68 | |
64 | 69 | $this->match['target_controller'] = $controller_class_name; |
65 | 70 | $this->match['target_method'] = $target_method; |
@@ -81,16 +86,19 @@ discard block |
||
81 | 86 | { |
82 | 87 | |
83 | 88 | // $key is null, returns $dat_ass or empty array |
84 | - if(is_null($key)) |
|
85 | - return $dat_ass ?? []; |
|
89 | + if(is_null($key)) { |
|
90 | + return $dat_ass ?? []; |
|
91 | + } |
|
86 | 92 | |
87 | 93 | // $dat_ass[$key] not set, returns null |
88 | - if(!isset($dat_ass[$key])) |
|
89 | - return null; |
|
94 | + if(!isset($dat_ass[$key])) { |
|
95 | + return null; |
|
96 | + } |
|
90 | 97 | |
91 | 98 | // $dat_ass[$key] is a string, returns decoded value |
92 | - if(is_string($dat_ass[$key])) |
|
93 | - return urldecode($dat_ass[$key]); |
|
99 | + if(is_string($dat_ass[$key])) { |
|
100 | + return urldecode($dat_ass[$key]); |
|
101 | + } |
|
94 | 102 | |
95 | 103 | // $dat_ass[$key] is not a string, return match[$key] |
96 | 104 | return $dat_ass[$key]; |
@@ -140,7 +148,7 @@ discard block |
||
140 | 148 | { |
141 | 149 | try{ |
142 | 150 | $url = $this->generate($route, $route_params); |
143 | - }catch(\Exception $e){ |
|
151 | + } catch(\Exception $e){ |
|
144 | 152 | $url = $this->prehop(self::ROUTE_HOME_NAME); |
145 | 153 | } |
146 | 154 | |
@@ -163,12 +171,13 @@ discard block |
||
163 | 171 | { |
164 | 172 | $url = null; |
165 | 173 | |
166 | - if(is_null($route)) |
|
167 | - $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params); |
|
168 | - elseif(is_string($route) && $this->route_exists($route)) |
|
169 | - $url = $this->prehop($route, $route_params); |
|
170 | - else |
|
171 | - $url = $route; |
|
174 | + if(is_null($route)) { |
|
175 | + $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params); |
|
176 | + } elseif(is_string($route) && $this->route_exists($route)) { |
|
177 | + $url = $this->prehop($route, $route_params); |
|
178 | + } else { |
|
179 | + $url = $route; |
|
180 | + } |
|
172 | 181 | |
173 | 182 | $this->hop_url($url); |
174 | 183 | } |
@@ -176,8 +185,9 @@ discard block |
||
176 | 185 | // hops back to previous page (referer()), or home if no referer |
177 | 186 | public function hop_back() |
178 | 187 | { |
179 | - if(!is_null($back = $this->referer())) |
|
180 | - $this->hop_url($back); |
|
188 | + if(!is_null($back = $this->referer())) { |
|
189 | + $this->hop_url($back); |
|
190 | + } |
|
181 | 191 | |
182 | 192 | $this->hop(); |
183 | 193 | } |
@@ -194,16 +204,18 @@ discard block |
||
194 | 204 | // returns null if same as current URL (prevents endless redirection loop) |
195 | 205 | public function referer() |
196 | 206 | { |
197 | - if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) |
|
198 | - return $_SERVER['HTTP_REFERER']; |
|
207 | + if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) { |
|
208 | + return $_SERVER['HTTP_REFERER']; |
|
209 | + } |
|
199 | 210 | |
200 | 211 | return null; |
201 | 212 | } |
202 | 213 | |
203 | 214 | public function send_file($file_path) |
204 | 215 | { |
205 | - if(!file_exists($file_path)) |
|
206 | - throw new RouterException('SENDING_NON_EXISTING_FILE'); |
|
216 | + if(!file_exists($file_path)) { |
|
217 | + throw new RouterException('SENDING_NON_EXISTING_FILE'); |
|
218 | + } |
|
207 | 219 | |
208 | 220 | $file_name = basename($file_path); |
209 | 221 |