@@ -58,19 +58,19 @@ discard block |
||
58 | 58 | $this->config()->set('api', false); |
59 | 59 | $this->config()->set('middlewares', []); |
60 | 60 | |
61 | - $this->handler('404', function () { |
|
61 | + $this->handler('404', function() { |
|
62 | 62 | if ($this->config()->get('api')) { |
63 | 63 | return ['status' => 404, 'msg' => '404 Not Found']; |
64 | 64 | } |
65 | 65 | return '404 Not Found'; |
66 | 66 | }); |
67 | - $this->handler('405', function () { |
|
67 | + $this->handler('405', function() { |
|
68 | 68 | if ($this->config()->get('api')) { |
69 | 69 | return ['status' => 405, 'msg' => '405 Method Not Allowed']; |
70 | 70 | } |
71 | 71 | return '405 Method Not Allowed'; |
72 | 72 | }); |
73 | - $this->handler('500', function () { |
|
73 | + $this->handler('500', function() { |
|
74 | 74 | if ($this->config()->get('api')) { |
75 | 75 | return ['status' => 500, 'msg' => '500 Internal Server Error']; |
76 | 76 | } |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * @param string $name |
98 | 98 | * @param \Closure|callable $callback |
99 | 99 | */ |
100 | - public function handler(string $name, \Closure|callable $callback): void |
|
100 | + public function handler(string $name, \Closure | callable $callback): void |
|
101 | 101 | { |
102 | - if(is_callable($callback)){ |
|
102 | + if (is_callable($callback)) { |
|
103 | 103 | $callback = \Closure::fromCallable(callback: $callback); |
104 | 104 | |
105 | 105 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param string $key |
116 | 116 | * @return \Closure|callable |
117 | 117 | */ |
118 | - public function getHandler($key): \Closure|callable |
|
118 | + public function getHandler($key): \Closure | callable |
|
119 | 119 | { |
120 | 120 | return $this->handler[$key]; |
121 | 121 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $request = $this->request(); |
133 | 133 | } |
134 | 134 | $pipeline = new Pipeline(); |
135 | - $response = $pipeline->middleware($this->config()->get('middlewares'))->run($request, function ($request) { |
|
135 | + $response = $pipeline->middleware($this->config()->get('middlewares'))->run($request, function($request) { |
|
136 | 136 | return $this->dispatchRouter($request); |
137 | 137 | }); |
138 | 138 | return $response; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param int $status |
221 | 221 | * @return \Scrawler\Http\Response |
222 | 222 | */ |
223 | - private function makeResponse(array|string|\Scrawler\Http\Response $content, int $status = 200): \Scrawler\Http\Response |
|
223 | + private function makeResponse(array | string | \Scrawler\Http\Response $content, int $status = 200): \Scrawler\Http\Response |
|
224 | 224 | { |
225 | 225 | if (!$content instanceof \Scrawler\Http\Response) { |
226 | 226 | $response = new \Scrawler\Http\Response(); |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | * Add middleware(s) |
269 | 269 | * @param \Closure|callable|array<callable>|string $middlewares |
270 | 270 | */ |
271 | - public function middleware(\Closure|callable|array|string $middlewares): void{ |
|
272 | - $this->config()->append('middlewares',$middlewares); |
|
271 | + public function middleware(\Closure | callable | array | string $middlewares): void{ |
|
272 | + $this->config()->append('middlewares', $middlewares); |
|
273 | 273 | $middlewares = $this->pipeline()->validateMiddleware(middlewares: $this->config()->get('middlewares')); |
274 | - $this->config()->set('middlewares',$middlewares); |
|
274 | + $this->config()->set('middlewares', $middlewares); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 |
@@ -45,11 +45,11 @@ |
||
45 | 45 | return $this->container->make($class, $params); |
46 | 46 | } |
47 | 47 | |
48 | - /** |
|
49 | - * Check if a class is registered in the container |
|
50 | - * @param string $class |
|
51 | - * @return bool |
|
52 | - */ |
|
48 | + /** |
|
49 | + * Check if a class is registered in the container |
|
50 | + * @param string $class |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | 53 | public function has(string $class): bool |
54 | 54 | { |
55 | 55 | return $this->container->has($class); |
@@ -8,12 +8,12 @@ discard block |
||
8 | 8 | * @param mixed $value |
9 | 9 | * @param bool $force |
10 | 10 | */ |
11 | - public function register($name, $value,bool $force = false): void |
|
11 | + public function register($name, $value, bool $force = false): void |
|
12 | 12 | { |
13 | - if($this->container->has($name) && !$force){ |
|
13 | + if ($this->container->has($name) && !$force) { |
|
14 | 14 | throw new \Scrawler\Exception\ContainerException('Service with this name already registered, please set $force = true to override'); |
15 | 15 | } |
16 | - if($this->container->has($name) && ($name == 'config' || $name == 'pipeline')){ |
|
16 | + if ($this->container->has($name) && ($name == 'config' || $name == 'pipeline')) { |
|
17 | 17 | throw new \Scrawler\Exception\ContainerException('Service with this name cannot be overridden'); |
18 | 18 | } |
19 | 19 | $this->container->set($name, $value); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param array<mixed> $params |
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - public function call(string|callable $class, array $params = []): mixed |
|
64 | + public function call(string | callable $class, array $params = []): mixed |
|
65 | 65 | { |
66 | 66 | return $this->container->call($class, $params); |
67 | 67 | } |
@@ -3,21 +3,21 @@ |
||
3 | 3 | |
4 | 4 | trait Router |
5 | 5 | { |
6 | - /** |
|
7 | - * Register controller directory and namespace for autorouting |
|
8 | - * @param string $dir |
|
9 | - * @param string $namespace |
|
10 | - */ |
|
6 | + /** |
|
7 | + * Register controller directory and namespace for autorouting |
|
8 | + * @param string $dir |
|
9 | + * @param string $namespace |
|
10 | + */ |
|
11 | 11 | public function registerAutoRoute(string $dir, string $namespace): void |
12 | 12 | { |
13 | 13 | $this->router->register($dir, $namespace); |
14 | 14 | } |
15 | 15 | |
16 | - /** |
|
17 | - * Register a new get route with the router |
|
18 | - * @param string $route |
|
19 | - * @param \Closure|callable $callback |
|
20 | - */ |
|
16 | + /** |
|
17 | + * Register a new get route with the router |
|
18 | + * @param string $route |
|
19 | + * @param \Closure|callable $callback |
|
20 | + */ |
|
21 | 21 | public function get(string $route, \Closure|callable $callback): void |
22 | 22 | { |
23 | 23 | if(is_callable($callback)){ |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | * @param string $route |
19 | 19 | * @param \Closure|callable $callback |
20 | 20 | */ |
21 | - public function get(string $route, \Closure|callable $callback): void |
|
21 | + public function get(string $route, \Closure | callable $callback): void |
|
22 | 22 | { |
23 | - if(is_callable($callback)){ |
|
23 | + if (is_callable($callback)) { |
|
24 | 24 | $callback = \Closure::fromCallable(callback: $callback); |
25 | 25 | } |
26 | 26 | $this->router->get($route, $callback); |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @param string $route |
32 | 32 | * @param \Closure|callable $callback |
33 | 33 | */ |
34 | - public function post(string $route, \Closure|callable $callback): void |
|
34 | + public function post(string $route, \Closure | callable $callback): void |
|
35 | 35 | { |
36 | - if(is_callable($callback)){ |
|
36 | + if (is_callable($callback)) { |
|
37 | 37 | $callback = \Closure::fromCallable(callback: $callback); |
38 | 38 | } |
39 | 39 | $this->router->post($route, $callback); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * @param string $route |
45 | 45 | * @param \Closure|callable $callback |
46 | 46 | */ |
47 | - public function put(string $route, \Closure|callable $callback): void |
|
47 | + public function put(string $route, \Closure | callable $callback): void |
|
48 | 48 | { |
49 | - if(is_callable($callback)){ |
|
49 | + if (is_callable($callback)) { |
|
50 | 50 | $callback = \Closure::fromCallable(callback: $callback); |
51 | 51 | } |
52 | 52 | $this->router->put($route, $callback); |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * @param string $route |
58 | 58 | * @param \Closure|callable $callback |
59 | 59 | */ |
60 | - public function delete(string $route, \Closure|callable $callback): void |
|
60 | + public function delete(string $route, \Closure | callable $callback): void |
|
61 | 61 | { |
62 | - if(is_callable($callback)){ |
|
62 | + if (is_callable($callback)) { |
|
63 | 63 | $callback = \Closure::fromCallable(callback: $callback); |
64 | 64 | } |
65 | 65 | $this->router->delete($route, $callback); |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * @param string $route |
71 | 71 | * @param \Closure|callable $callback |
72 | 72 | */ |
73 | - public function all(string $route,\Closure|callable $callback): void |
|
73 | + public function all(string $route, \Closure | callable $callback): void |
|
74 | 74 | { |
75 | - if(is_callable($callback)){ |
|
75 | + if (is_callable($callback)) { |
|
76 | 76 | $callback = \Closure::fromCallable(callback: $callback); |
77 | 77 | } |
78 | 78 | $this->router->all($route, $callback); |