@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace HnrAzevedo\Router; |
6 | 6 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | $route = self::getInstance()->inSave(); |
36 | 36 | |
37 | - if(null === $value){ |
|
37 | + if (null === $value) { |
|
38 | 38 | return (isset($route['attributes'][$name])) ? $route['attributes'][$name] : null; |
39 | 39 | } |
40 | 40 | |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | public static function groupAttribute(string $name, $value = null, ?array $excepts = []): Router |
48 | 48 | { |
49 | 49 | $group = self::getInstance()->inSave()['group']; |
50 | - foreach(self::getInstance()->getRoutes() as $r => $route){ |
|
51 | - if($route['group'] !== $group || in_array($route['name'], $excepts)){ |
|
50 | + foreach (self::getInstance()->getRoutes() as $r => $route) { |
|
51 | + if ($route['group'] !== $group || in_array($route['name'], $excepts)) { |
|
52 | 52 | continue; |
53 | 53 | } |
54 | 54 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public static function group(string $prefix, \Closure $closure): Router |
62 | 62 | { |
63 | 63 | $id = sha1(date('d/m/Y h:m:i')); |
64 | - while(array_key_exists($id, self::getInstance()->groupsName)){ |
|
64 | + while (array_key_exists($id, self::getInstance()->groupsName)) { |
|
65 | 65 | $id = sha1(date('d/m/Y h:m:i').$id); |
66 | 66 | } |
67 | 67 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | { |
83 | 83 | self::getInstance()->loaded = true; |
84 | 84 | |
85 | - if(null !== $name){ |
|
85 | + if (null !== $name) { |
|
86 | 86 | return self::getInstance()->loadByName($name); |
87 | 87 | } |
88 | 88 | |
@@ -90,15 +90,15 @@ discard block |
||
90 | 90 | |
91 | 91 | $requestMethod = (isset($_REQUEST['REQUEST_METHOD'])) ? $_REQUEST['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']; |
92 | 92 | |
93 | - foreach(self::getInstance()->getRoutes() as $r => $route){ |
|
93 | + foreach (self::getInstance()->getRoutes() as $r => $route) { |
|
94 | 94 | self::getInstance()->currentRoute = $route; |
95 | 95 | self::getInstance()->currentRoute['name'] = $r; |
96 | 96 | |
97 | - try{ |
|
97 | + try { |
|
98 | 98 | self::getInstance()->checkMethod($route, $requestMethod); |
99 | 99 | self::getInstance()->checkData($route, (new Uri($_SERVER['REQUEST_URI']))->getPath()); |
100 | 100 | return self::getInstance(); |
101 | - }catch(\Exception $er){ |
|
101 | + }catch (\Exception $er) { |
|
102 | 102 | continue; |
103 | 103 | } |
104 | 104 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | public static function run(?string $name = null): RouterInterface |
114 | 114 | { |
115 | - if(!self::getInstance()->loaded){ |
|
115 | + if (!self::getInstance()->loaded) { |
|
116 | 116 | self::getInstance()->load($name); |
117 | 117 | } |
118 | 118 | |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | |
123 | 123 | self::getInstance()->executeBefore(); |
124 | 124 | |
125 | - try{ |
|
125 | + try { |
|
126 | 126 | $action = unserialize(self::getInstance()->current()['action']); |
127 | - self::getInstance()->executeRouteAction( (is_string($action)) ? $action : $action->getClosure() ); |
|
128 | - }catch(\Exception $er){ |
|
127 | + self::getInstance()->executeRouteAction((is_string($action)) ? $action : $action->getClosure()); |
|
128 | + }catch (\Exception $er) { |
|
129 | 129 | self::getInstance()->error = $er; |
130 | 130 | } |
131 | 131 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | private function checkError(): void |
140 | 140 | { |
141 | - if(isset($this->error)){ |
|
141 | + if (isset($this->error)) { |
|
142 | 142 | throw $this->error; |
143 | 143 | } |
144 | 144 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | |
153 | 153 | public static function routes(?array $routes = null): array |
154 | 154 | { |
155 | - if(null !== $routes){ |
|
155 | + if (null !== $routes) { |
|
156 | 156 | self::getInstance()->setRoutes($routes); |
157 | 157 | self::getInstance()->sortRoutes(); |
158 | 158 | } |