@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Defines a route for the GET method |
9 | 9 | */ |
10 | -Router::get('/foo','HnrAzevedo\Router\Example\Controllers\Controller@method'); |
|
10 | +Router::get('/foo', 'HnrAzevedo\Router\Example\Controllers\Controller@method'); |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Defines a route to the GET method with an anonymous function |
14 | 14 | */ |
15 | -Router::get('/bar', function(){ |
|
15 | +Router::get('/bar', function() { |
|
16 | 16 | // |
17 | 17 | echo '/bar executed!'; |
18 | 18 | }); |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Defines a route to the POST method with an anonymous function |
22 | 22 | */ |
23 | -Router::post('/bar', function(){ |
|
23 | +Router::post('/bar', function() { |
|
24 | 24 | // |
25 | 25 | }); |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Defining route for any method |
29 | 29 | */ |
30 | -Router::any('/any', function(){ |
|
30 | +Router::any('/any', function() { |
|
31 | 31 | // |
32 | 32 | }); |
33 | 33 | |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | * @param string $route |
38 | 38 | * @param \Closure|string $action |
39 | 39 | */ |
40 | -Router::match('GET|post', '/get_post', function(){ |
|
40 | +Router::match('GET|post', '/get_post', function() { |
|
41 | 41 | // |
42 | 42 | }); |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Defines the route name |
46 | 46 | */ |
47 | -Router::get('/named', function(){ |
|
47 | +Router::get('/named', function() { |
|
48 | 48 | // |
49 | 49 | })->name('baz'); |
50 | 50 | |
@@ -56,32 +56,32 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * Run before all requests, regardless of error occurrences |
58 | 58 | */ |
59 | -Router::beforeAll(function(){ |
|
59 | +Router::beforeAll(function() { |
|
60 | 60 | // |
61 | 61 | }, null); |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Run after all requests, regardless of error occurrences |
65 | 65 | */ |
66 | -Router::afterAll(function(){ |
|
66 | +Router::afterAll(function() { |
|
67 | 67 | // |
68 | 68 | }, null); |
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Executes after executing the triggered route action |
72 | 72 | */ |
73 | -Router::get('/after', function(){ |
|
73 | +Router::get('/after', function() { |
|
74 | 74 | // |
75 | -})->after(function(){ |
|
75 | +})->after(function() { |
|
76 | 76 | // |
77 | 77 | }); |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Executes before executing the triggered route action |
81 | 81 | */ |
82 | -Router::get('/before', function(){ |
|
82 | +Router::get('/before', function() { |
|
83 | 83 | // |
84 | -})->before(function(){ |
|
84 | +})->before(function() { |
|
85 | 85 | // |
86 | 86 | }); |
87 | 87 | /** |
@@ -102,21 +102,21 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * Example of route definition with parameters |
104 | 104 | */ |
105 | -Router::get('/passingParameters/{param}', function($param){ |
|
105 | +Router::get('/passingParameters/{param}', function($param) { |
|
106 | 106 | echo $param; |
107 | 107 | }); |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Example of setting an optional parameter |
111 | 111 | */ |
112 | -Router::get('/passingParameters/{?optionalParam}', function($optionalParam){ |
|
112 | +Router::get('/passingParameters/{?optionalParam}', function($optionalParam) { |
|
113 | 113 | echo $optionalParam; |
114 | 114 | }); |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * Example of regular expression test for parameters |
118 | 118 | */ |
119 | -Router::get('/testingParameters/{param}', function($param){ |
|
119 | +Router::get('/testingParameters/{param}', function($param) { |
|
120 | 120 | echo $param; |
121 | 121 | })->where([ |
122 | 122 | 'param'=>'[0-9]{1,11}' |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | * @param string $prefix |
133 | 133 | * @param \Closure $routeDefinitions |
134 | 134 | */ |
135 | -Router::group('/admin', function(){ |
|
136 | - Router::get('/users/{teste}', function($teste){ |
|
135 | +Router::group('/admin', function() { |
|
136 | + Router::get('/users/{teste}', function($teste) { |
|
137 | 137 | echo $teste; |
138 | 138 | })->where([ |
139 | 139 | 'teste'=>'[a-zA-Z]*' |
140 | 140 | ]); |
141 | 141 | }); |
142 | 142 | |
143 | -Router::group('/admin2', function(){ |
|
144 | - Router::get('/users/{teste}', function($teste){ |
|
143 | +Router::group('/admin2', function() { |
|
144 | + Router::get('/users/{teste}', function($teste) { |
|
145 | 145 | echo $teste; |
146 | 146 | })->name('teste'); |
147 | 147 | }) |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | ->groupWhere([ |
154 | 154 | 'teste'=>'[a-zA-Z]*' |
155 | -],[]); |
|
155 | +], []); |
|
156 | 156 | |
157 | 157 | |
158 | 158 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | /** |
170 | 170 | * Defining route middleware - implements Psr\Http\Server\MiddlewareInterface |
171 | 171 | */ |
172 | -Router::get('/passingParameters/{?optionalParam}', function($optionalParam = null){ |
|
172 | +Router::get('/passingParameters/{?optionalParam}', function($optionalParam = null) { |
|
173 | 173 | echo $optionalParam; |
174 | 174 | })->middleware([ |
175 | 175 | HnrAzevedo\Router\Example\Middleware\Auth::class |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | /** |
179 | 179 | * Defining middleware by nickname |
180 | 180 | */ |
181 | -Router::get('/lasted', function(){ |
|
181 | +Router::get('/lasted', function() { |
|
182 | 182 | // |
183 | 183 | })->middleware([ |
184 | 184 | 'Lasted' |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * Defining multiple middlewares |
189 | 189 | * NOTE: Importantly, the execution follows the same order of definition |
190 | 190 | */ |
191 | -Router::get('/middlewares', function(){ |
|
191 | +Router::get('/middlewares', function() { |
|
192 | 192 | // |
193 | 193 | })->middleware([ |
194 | 194 | HnrAzevedo\Router\Example\Middleware\Auth::class, |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | use HnrAzevedo\Router\Router; |
9 | 9 | |
10 | -try{ |
|
10 | +try { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Add to composer.json autoload |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | $action = Router::currentAction(); |
37 | 37 | |
38 | -}catch(Exception $er){ |
|
38 | +}catch (Exception $er) { |
|
39 | 39 | |
40 | 40 | die("Code Error: {$er->getCode()}".PHP_EOL."Line: {$er->getLine()}".PHP_EOL."File: {$er->getFile()}".PHP_EOL."Message: {$er->getMessage()}."); |
41 | 41 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | */ |
36 | 36 | $action = Router::currentAction(); |
37 | 37 | |
38 | -}catch(Exception $er){ |
|
38 | +} catch(Exception $er){ |
|
39 | 39 | |
40 | 40 | die("Code Error: {$er->getCode()}".PHP_EOL."Line: {$er->getLine()}".PHP_EOL."File: {$er->getFile()}".PHP_EOL."Message: {$er->getMessage()}."); |
41 | 41 |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use HnrAzevedo\Router\RouteAttribute; |
6 | 6 | |
7 | -class ControllerAttribute{ |
|
7 | +class ControllerAttribute { |
|
8 | 8 | |
9 | 9 | #[RouteAttribute( |
10 | 10 | uri:'/fooo/{param}', |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Router\Example\Controllers; |
4 | 4 | |
5 | -class Controller{ |
|
5 | +class Controller { |
|
6 | 6 | |
7 | 7 | public function method(): void |
8 | 8 | { |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | use HnrAzevedo\Router\Router; |
15 | 15 | use Psr\Http\Server\MiddlewareInterface; |
16 | 16 | |
17 | -try{ |
|
17 | +try { |
|
18 | 18 | $requestMethod = (isset($_REQUEST['REQUEST_METHOD'])) ? $_REQUEST['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']; |
19 | 19 | |
20 | 20 | $serverRequest = (new Factory())->createServerRequest($requestMethod, new Uri($_SERVER['REQUEST_URI'])); |
21 | 21 | |
22 | - class App implements MiddlewareInterface{ |
|
22 | + class App implements MiddlewareInterface { |
|
23 | 23 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
24 | 24 | { |
25 | - if(empty($request->getAttribute('route'))) |
|
25 | + if (empty($request->getAttribute('route'))) |
|
26 | 26 | { |
27 | 27 | throw new Exception('Page not found', 404); |
28 | 28 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
36 | - define('GLOBAL_MIDDLEWARES',[ |
|
36 | + define('GLOBAL_MIDDLEWARES', [ |
|
37 | 37 | Router::class, |
38 | 38 | App::class |
39 | 39 | ]); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | function runMiddlewares($serverRequest) |
71 | 71 | { |
72 | - nextExample(new class implements RequestHandlerInterface{ |
|
72 | + nextExample(new class implements RequestHandlerInterface { |
|
73 | 73 | public function handle(ServerRequestInterface $request): ResponseInterface |
74 | 74 | { |
75 | 75 | return (new Factory())->createResponse(200); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | runMiddlewares($serverRequest); |
81 | 81 | |
82 | -}catch(Exception $er){ |
|
82 | +}catch (Exception $er) { |
|
83 | 83 | |
84 | 84 | die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}."); |
85 | 85 |