@@ -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 | |
@@ -29,17 +29,17 @@ discard block |
||
29 | 29 | |
30 | 30 | public static function loadPipeline(): void |
31 | 31 | { |
32 | - foreach(self::getInstance()->getPipeline() as $path){ |
|
32 | + foreach (self::getInstance()->getPipeline() as $path) { |
|
33 | 33 | |
34 | - if(!is_dir($path)){ |
|
34 | + if (!is_dir($path)) { |
|
35 | 35 | self::getInstance()->loadLine(new ReflectionObject(new $path())); |
36 | 36 | continue; |
37 | 37 | }; |
38 | 38 | |
39 | 39 | foreach (scandir($path) as $routeFile) { |
40 | - if(pathinfo($path . DIRECTORY_SEPARATOR . $routeFile, PATHINFO_EXTENSION) === 'php'){ |
|
40 | + if (pathinfo($path.DIRECTORY_SEPARATOR.$routeFile, PATHINFO_EXTENSION) === 'php') { |
|
41 | 41 | |
42 | - require_once($path . DIRECTORY_SEPARATOR . $routeFile); |
|
42 | + require_once($path.DIRECTORY_SEPARATOR.$routeFile); |
|
43 | 43 | |
44 | 44 | $classes = get_declared_classes(); |
45 | 45 | $className = end($classes); |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | |
52 | 52 | private function loadLine(ReflectionObject $reflection): void |
53 | 53 | { |
54 | - foreach($reflection->getMethods() as $method){ |
|
54 | + foreach ($reflection->getMethods() as $method) { |
|
55 | 55 | $this->loadMethod($method); |
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | 59 | private function loadMethod(ReflectionMethod $method): void |
60 | 60 | { |
61 | - try{ |
|
61 | + try { |
|
62 | 62 | foreach ($method->getAttributes() as $attr) { |
63 | - if($attr->getName() != 'HnrAzevedo\Router\Route') continue; |
|
63 | + if ($attr->getName() != 'HnrAzevedo\Router\Route') continue; |
|
64 | 64 | |
65 | 65 | $args = $attr->getArguments(); |
66 | 66 | |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | ->attrWhere($args) |
80 | 80 | ->attrMiddleware($args); |
81 | 81 | } |
82 | - }catch(Exception $er){ |
|
82 | + }catch (Exception $er) { |
|
83 | 83 | throw new Exception('Failed to add route via attribute: '.$er->getMessage()); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | 87 | private function checkArgs(array $args): self |
88 | 88 | { |
89 | - if(!array_key_exists('uri', $args) && !array_key_exists(0, $args)) { |
|
89 | + if (!array_key_exists('uri', $args) && !array_key_exists(0, $args)) { |
|
90 | 90 | throw new Exception('Misconfigured route attribute'); |
91 | 91 | } |
92 | 92 | return $this; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | private function attrName(array $attr): self |
96 | 96 | { |
97 | - if(array_key_exists('name', $attr)) { |
|
97 | + if (array_key_exists('name', $attr)) { |
|
98 | 98 | self::getInstance()->name($attr['name']); |
99 | 99 | } |
100 | 100 | return $this; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | private function attrBefore(array $attr): self |
104 | 104 | { |
105 | - if(array_key_exists('before', $attr)) { |
|
105 | + if (array_key_exists('before', $attr)) { |
|
106 | 106 | self::getInstance()->before($attr['before']); |
107 | 107 | } |
108 | 108 | return $this; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | private function attrAfter(array $attr): self |
112 | 112 | { |
113 | - if(array_key_exists('after', $attr)) { |
|
113 | + if (array_key_exists('after', $attr)) { |
|
114 | 114 | self::getInstance()->after($attr['after']); |
115 | 115 | } |
116 | 116 | return $this; |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | |
119 | 119 | private function attrAttributes(array $attr): self |
120 | 120 | { |
121 | - if(array_key_exists('attributes', $attr)) { |
|
122 | - foreach($attr['attributes'] as $attribute => $attrValue){ |
|
121 | + if (array_key_exists('attributes', $attr)) { |
|
122 | + foreach ($attr['attributes'] as $attribute => $attrValue) { |
|
123 | 123 | self::getInstance()->attribute($attribute, $attrValue); |
124 | 124 | } |
125 | 125 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | private function attrWhere(array $attr): self |
130 | 130 | { |
131 | - if(array_key_exists('where', $attr)) { |
|
131 | + if (array_key_exists('where', $attr)) { |
|
132 | 132 | self::getInstance()->where($attr['where']); |
133 | 133 | } |
134 | 134 | return $this; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | private function attrMiddleware(array $attr): self |
138 | 138 | { |
139 | - if(array_key_exists('middleware', $attr)) { |
|
139 | + if (array_key_exists('middleware', $attr)) { |
|
140 | 140 | self::getInstance()->middleware($attr['middleware']); |
141 | 141 | } |
142 | 142 | return $this; |