@@ -11,7 +11,7 @@ |
||
| 11 | 11 | |
| 12 | 12 | Router::create()->dispatch(); |
| 13 | 13 | |
| 14 | -}catch(Exception $er){ |
|
| 14 | +} catch(Exception $er){ |
|
| 15 | 15 | |
| 16 | 16 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 17 | 17 | |
@@ -61,23 +61,23 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public function set($url , $role , $protocol = null): Router |
| 63 | 63 | { |
| 64 | - $url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url; |
|
| 64 | + $url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url; |
|
| 65 | 65 | |
| 66 | - foreach($this->routers as $key => $value){ |
|
| 67 | - if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){ |
|
| 66 | + foreach($this->routers as $key => $value){ |
|
| 67 | + if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){ |
|
| 68 | 68 | throw new Exception("There is already a route with the url {$url} and with the {$protocol} protocol configured."); |
| 69 | 69 | } |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $route = [ |
|
| 73 | - 'url' => $this->prefix.$url, |
|
| 74 | - 'role' => $role, |
|
| 75 | - 'protocol' => $protocol, |
|
| 76 | - 'filters' => null, |
|
| 72 | + $route = [ |
|
| 73 | + 'url' => $this->prefix.$url, |
|
| 74 | + 'role' => $role, |
|
| 75 | + 'protocol' => $protocol, |
|
| 76 | + 'filters' => null, |
|
| 77 | 77 | 'group' => self::getInstance()->group |
| 78 | - ]; |
|
| 78 | + ]; |
|
| 79 | 79 | |
| 80 | - $this->routers[] = $route; |
|
| 80 | + $this->routers[] = $route; |
|
| 81 | 81 | |
| 82 | 82 | return self::getInstance(); |
| 83 | 83 | } |
@@ -139,13 +139,13 @@ discard block |
||
| 139 | 139 | return $this->byName($route_name); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $currentProtocol = $this->getProtocol(); |
|
| 142 | + $currentProtocol = $this->getProtocol(); |
|
| 143 | 143 | |
| 144 | 144 | foreach(array_reverse($this->routers) as $r => $route){ |
| 145 | 145 | |
| 146 | 146 | $this->hasProtocol($route, $currentProtocol); |
| 147 | 147 | |
| 148 | - $route_loop = explode( |
|
| 148 | + $route_loop = explode( |
|
| 149 | 149 | '/', |
| 150 | 150 | (substr($route['url'],strlen($route['url'])-1,1) === '/') |
| 151 | 151 | ? substr($route['url'], 0, -1) |
@@ -159,17 +159,17 @@ discard block |
||
| 159 | 159 | : $_SERVER['REQUEST_URI'] |
| 160 | 160 | ); |
| 161 | 161 | |
| 162 | - if($this->check_numparams($route_loop, $route_request)){ |
|
| 162 | + if($this->check_numparams($route_loop, $route_request)){ |
|
| 163 | 163 | continue; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - for($rr = 0; $rr < count($route_loop); $rr++){ |
|
| 166 | + for($rr = 0; $rr < count($route_loop); $rr++){ |
|
| 167 | 167 | |
| 168 | - if( (substr($route_loop[$rr],0,1) === '{') ){ |
|
| 168 | + if( (substr($route_loop[$rr],0,1) === '{') ){ |
|
| 169 | 169 | $data[ substr($route_loop[$rr],1,strlen($route_loop[$rr])-2) ] = $route_request[$rr]; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if($this->check_parameter($route_loop[$rr], $route_request[$rr])){ |
|
| 172 | + if($this->check_parameter($route_loop[$rr], $route_request[$rr])){ |
|
| 173 | 173 | continue 2; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | $this->check_filtering($route); |
| 179 | 179 | |
| 180 | 180 | $this->Controller($route['role']); |
| 181 | - return true; |
|
| 182 | - } |
|
| 181 | + return true; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - throw new Exception('Page not found.',404); |
|
| 184 | + throw new Exception('Page not found.',404); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | public static function filter($filters): Router |