@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | $this->config()->set('api', false); |
57 | 57 | $this->config()->set('middlewares', []); |
58 | 58 | |
59 | - $this->handler('404', function () { |
|
59 | + $this->handler('404', function() { |
|
60 | 60 | if ($this->config()->get('api')) { |
61 | 61 | return ['status' => 404, 'msg' => '404 Not Found']; |
62 | 62 | } |
63 | 63 | return '404 Not Found'; |
64 | 64 | }); |
65 | - $this->handler('405', function () { |
|
65 | + $this->handler('405', function() { |
|
66 | 66 | if ($this->config()->get('api')) { |
67 | 67 | return ['status' => 405, 'msg' => '405 Method Not Allowed']; |
68 | 68 | } |
69 | 69 | return '405 Method Not Allowed'; |
70 | 70 | }); |
71 | - $this->handler('500', function () { |
|
71 | + $this->handler('500', function() { |
|
72 | 72 | if ($this->config()->get('api')) { |
73 | 73 | return ['status' => 500, 'msg' => '500 Internal Server Error']; |
74 | 74 | } |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * @param string $route |
104 | 104 | * @param \Closure|callable $callback |
105 | 105 | */ |
106 | - public function get(string $route, \Closure|callable $callback): void |
|
106 | + public function get(string $route, \Closure | callable $callback): void |
|
107 | 107 | { |
108 | - if(is_callable($callback)){ |
|
108 | + if (is_callable($callback)) { |
|
109 | 109 | $callback = \Closure::fromCallable(callback: $callback); |
110 | 110 | } |
111 | 111 | $this->router->get($route, $callback); |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | * @param string $route |
117 | 117 | * @param \Closure|callable $callback |
118 | 118 | */ |
119 | - public function post(string $route, \Closure|callable $callback): void |
|
119 | + public function post(string $route, \Closure | callable $callback): void |
|
120 | 120 | { |
121 | - if(is_callable($callback)){ |
|
121 | + if (is_callable($callback)) { |
|
122 | 122 | $callback = \Closure::fromCallable(callback: $callback); |
123 | 123 | } |
124 | 124 | $this->router->post($route, $callback); |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | * @param string $route |
130 | 130 | * @param \Closure|callable $callback |
131 | 131 | */ |
132 | - public function put(string $route, \Closure|callable $callback): void |
|
132 | + public function put(string $route, \Closure | callable $callback): void |
|
133 | 133 | { |
134 | - if(is_callable($callback)){ |
|
134 | + if (is_callable($callback)) { |
|
135 | 135 | $callback = \Closure::fromCallable(callback: $callback); |
136 | 136 | } |
137 | 137 | $this->router->put($route, $callback); |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @param string $route |
143 | 143 | * @param \Closure|callable $callback |
144 | 144 | */ |
145 | - public function delete(string $route, \Closure|callable $callback): void |
|
145 | + public function delete(string $route, \Closure | callable $callback): void |
|
146 | 146 | { |
147 | - if(is_callable($callback)){ |
|
147 | + if (is_callable($callback)) { |
|
148 | 148 | $callback = \Closure::fromCallable(callback: $callback); |
149 | 149 | } |
150 | 150 | $this->router->delete($route, $callback); |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * @param string $route |
156 | 156 | * @param \Closure|callable $callback |
157 | 157 | */ |
158 | - public function all(string $route,\Closure|callable $callback): void |
|
158 | + public function all(string $route, \Closure | callable $callback): void |
|
159 | 159 | { |
160 | - if(is_callable($callback)){ |
|
160 | + if (is_callable($callback)) { |
|
161 | 161 | $callback = \Closure::fromCallable(callback: $callback); |
162 | 162 | } |
163 | 163 | $this->router->all($route, $callback); |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @param string $name |
170 | 170 | * @param \Closure|callable $callback |
171 | 171 | */ |
172 | - public function handler(string $name, \Closure|callable $callback): void |
|
172 | + public function handler(string $name, \Closure | callable $callback): void |
|
173 | 173 | { |
174 | - if(is_callable($callback)){ |
|
174 | + if (is_callable($callback)) { |
|
175 | 175 | $callback = \Closure::fromCallable(callback: $callback); |
176 | 176 | |
177 | 177 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param string $key |
188 | 188 | * @return \Closure|callable |
189 | 189 | */ |
190 | - public function getHandler($key): \Closure|callable |
|
190 | + public function getHandler($key): \Closure | callable |
|
191 | 191 | { |
192 | 192 | return $this->handler[$key]; |
193 | 193 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $request = $this->request(); |
205 | 205 | } |
206 | 206 | $pipeline = new Pipeline(); |
207 | - $response = $pipeline->middleware($this->config()->get('middlewares'))->run($request, function ($request) { |
|
207 | + $response = $pipeline->middleware($this->config()->get('middlewares'))->run($request, function($request) { |
|
208 | 208 | return $this->dispatchRouter($request); |
209 | 209 | }); |
210 | 210 | return $response; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param int $status |
271 | 271 | * @return \Scrawler\Http\Response |
272 | 272 | */ |
273 | - private function makeResponse(array|string|\Scrawler\Http\Response $content, int $status = 200): \Scrawler\Http\Response |
|
273 | + private function makeResponse(array | string | \Scrawler\Http\Response $content, int $status = 200): \Scrawler\Http\Response |
|
274 | 274 | { |
275 | 275 | if (!$content instanceof \Scrawler\Http\Response) { |
276 | 276 | $response = new \Scrawler\Http\Response(); |
@@ -318,10 +318,10 @@ discard block |
||
318 | 318 | * Add middleware(s) |
319 | 319 | * @param \Closure|callable|array<callable>|string $middlewares |
320 | 320 | */ |
321 | - public function middleware(\Closure|callable|array|string $middlewares): void{ |
|
322 | - $this->config()->append('middlewares',$middlewares); |
|
321 | + public function middleware(\Closure | callable | array | string $middlewares): void{ |
|
322 | + $this->config()->append('middlewares', $middlewares); |
|
323 | 323 | $middlewares = $this->pipeline()->validateMiddleware(middlewares: $this->config()->get('middlewares')); |
324 | - $this->config()->set('middlewares',$middlewares); |
|
324 | + $this->config()->set('middlewares', $middlewares); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | * @param mixed $value |
331 | 331 | * @param bool $force |
332 | 332 | */ |
333 | - public function register($name, $value,bool $force = false): void |
|
333 | + public function register($name, $value, bool $force = false): void |
|
334 | 334 | { |
335 | - if($this->container->has($name) && !$force){ |
|
335 | + if ($this->container->has($name) && !$force) { |
|
336 | 336 | throw new \Scrawler\Exception\ContainerException('Service with this name already registered, please set $force = true to override'); |
337 | 337 | } |
338 | - if($this->container->has($name) && ($name == 'config' || $name == 'pipeline')){ |
|
338 | + if ($this->container->has($name) && ($name == 'config' || $name == 'pipeline')) { |
|
339 | 339 | throw new \Scrawler\Exception\ContainerException('Service with this name cannot be overridden'); |
340 | 340 | } |
341 | 341 | $this->container->set($name, $value); |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | * @param array<mixed> $params |
383 | 383 | * @return mixed |
384 | 384 | */ |
385 | - public function call(string|callable $class, array $params = []): mixed |
|
385 | + public function call(string | callable $class, array $params = []): mixed |
|
386 | 386 | { |
387 | 387 | return $this->container->call($class, $params); |
388 | 388 | } |
@@ -51,17 +51,17 @@ |
||
51 | 51 | */ |
52 | 52 | function env(string $key):mixed |
53 | 53 | { |
54 | - if (isset($_ENV[$key])) { |
|
54 | + if (isset($_ENV[$key])) { |
|
55 | 55 | return $_ENV[$key]; |
56 | - } |
|
57 | - if(getenv($key)){ |
|
56 | + } |
|
57 | + if(getenv($key)){ |
|
58 | 58 | return getenv($key); |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - if(request()->server->has($key)){ |
|
61 | + if(request()->server->has($key)){ |
|
62 | 62 | return request()->server->get($key); |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - return null; |
|
65 | + return null; |
|
66 | 66 | } |
67 | 67 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | declare(strict_types=1); |
3 | 3 | |
4 | 4 | |
5 | -if(!function_exists('app')){ |
|
5 | +if (!function_exists('app')) { |
|
6 | 6 | /** |
7 | 7 | * Get the app instance |
8 | 8 | * |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | } |
17 | 17 | |
18 | -if(!function_exists('config')){ |
|
18 | +if (!function_exists('config')) { |
|
19 | 19 | /** |
20 | 20 | * Get the config instance |
21 | 21 | * |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | -if (! function_exists('url')) { |
|
29 | +if (!function_exists('url')) { |
|
30 | 30 | /** |
31 | 31 | * Generate a url |
32 | 32 | * |
33 | 33 | * @param string $path |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - function url(string $path='') |
|
36 | + function url(string $path = '') |
|
37 | 37 | { |
38 | 38 | if (\Scrawler\App::engine()->config()->has('https') && \Scrawler\App::engine()->config()->get('https')) { |
39 | 39 | return 'https://'.\Scrawler\App::engine()->request()->getHttpHost().\Scrawler\App::engine()->request()->getBasePath().$path; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | -if (! function_exists('env')) { |
|
45 | +if (!function_exists('env')) { |
|
46 | 46 | /** |
47 | 47 | * Get the value of an environment variable |
48 | 48 | * |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | if (isset($_ENV[$key])) { |
55 | 55 | return $_ENV[$key]; |
56 | 56 | } |
57 | - if(getenv($key)){ |
|
57 | + if (getenv($key)) { |
|
58 | 58 | return getenv($key); |
59 | 59 | } |
60 | 60 | |
61 | - if(request()->server->has($key)){ |
|
61 | + if (request()->server->has($key)) { |
|
62 | 62 | return request()->server->get($key); |
63 | 63 | } |
64 | 64 |
@@ -69,15 +69,15 @@ |
||
69 | 69 | $refFunction = new \ReflectionFunction($middleware); |
70 | 70 | $parameters = $refFunction->getParameters(); |
71 | 71 | foreach ($parameters as $parameter) { |
72 | - if($parameter->getName() == 'request' && $parameter->getType() != 'Scrawler\Http\Request') { |
|
73 | - throw new \Scrawler\Exception\InvalidMiddlewareException('First parameter of middleware must be of type Scrawler\Http\Request'); |
|
74 | - } |
|
75 | - if($parameter->getName() == 'next' && $parameter->getType() != 'Closure') { |
|
76 | - throw new \Scrawler\Exception\InvalidMiddlewareException('Second parameter of middleware must be of type Closure'); |
|
77 | - } |
|
78 | - if($parameter->getName() != 'request' && $parameter->getName() != 'next' ) { |
|
79 | - throw new \Scrawler\Exception\InvalidMiddlewareException('Invalid parameter name in middleware'); |
|
80 | - } |
|
72 | + if($parameter->getName() == 'request' && $parameter->getType() != 'Scrawler\Http\Request') { |
|
73 | + throw new \Scrawler\Exception\InvalidMiddlewareException('First parameter of middleware must be of type Scrawler\Http\Request'); |
|
74 | + } |
|
75 | + if($parameter->getName() == 'next' && $parameter->getType() != 'Closure') { |
|
76 | + throw new \Scrawler\Exception\InvalidMiddlewareException('Second parameter of middleware must be of type Closure'); |
|
77 | + } |
|
78 | + if($parameter->getName() != 'request' && $parameter->getName() != 'next' ) { |
|
79 | + throw new \Scrawler\Exception\InvalidMiddlewareException('Invalid parameter name in middleware'); |
|
80 | + } |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | public function validateMiddleware(array $middlewares): array |
38 | 38 | { |
39 | 39 | $validated = []; |
40 | - if(is_array($middlewares) ) { |
|
40 | + if (is_array($middlewares)) { |
|
41 | 41 | foreach ($middlewares as $middleware) { |
42 | - if(is_string($middleware)) { |
|
43 | - if(class_exists($middleware)) { |
|
42 | + if (is_string($middleware)) { |
|
43 | + if (class_exists($middleware)) { |
|
44 | 44 | $middlewareObj = new $middleware; |
45 | - if($middlewareObj instanceof MiddlewareInterface) { |
|
45 | + if ($middlewareObj instanceof MiddlewareInterface) { |
|
46 | 46 | $callable = [$middlewareObj, 'run']; |
47 | 47 | $middleware = \Closure::fromCallable(callback: $callable); |
48 | 48 | } else { |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | } |
56 | - if(is_callable($middleware)) { |
|
56 | + if (is_callable($middleware)) { |
|
57 | 57 | $middleware = \Closure::fromCallable(callback: $middleware); |
58 | 58 | } |
59 | 59 | $this->validateClosure($middleware); |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | $refFunction = new \ReflectionFunction($middleware); |
70 | 70 | $parameters = $refFunction->getParameters(); |
71 | 71 | foreach ($parameters as $parameter) { |
72 | - if($parameter->getName() == 'request' && $parameter->getType() != 'Scrawler\Http\Request') { |
|
72 | + if ($parameter->getName() == 'request' && $parameter->getType() != 'Scrawler\Http\Request') { |
|
73 | 73 | throw new \Scrawler\Exception\InvalidMiddlewareException('First parameter of middleware must be of type Scrawler\Http\Request'); |
74 | 74 | } |
75 | - if($parameter->getName() == 'next' && $parameter->getType() != 'Closure') { |
|
75 | + if ($parameter->getName() == 'next' && $parameter->getType() != 'Closure') { |
|
76 | 76 | throw new \Scrawler\Exception\InvalidMiddlewareException('Second parameter of middleware must be of type Closure'); |
77 | 77 | } |
78 | - if($parameter->getName() != 'request' && $parameter->getName() != 'next' ) { |
|
78 | + if ($parameter->getName() != 'request' && $parameter->getName() != 'next') { |
|
79 | 79 | throw new \Scrawler\Exception\InvalidMiddlewareException('Invalid parameter name in middleware'); |
80 | 80 | } |
81 | 81 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $middlewares = array_reverse($this->middlewares); |
107 | 107 | |
108 | 108 | |
109 | - $completePipeline = array_reduce($middlewares, function ($nextMiddleware, $middleware) { |
|
109 | + $completePipeline = array_reduce($middlewares, function($nextMiddleware, $middleware) { |
|
110 | 110 | return $this->createMiddleware($nextMiddleware, $middleware); |
111 | 111 | }, $coreFunction); |
112 | 112 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | private function createCoreFunction(\Closure $core) |
125 | 125 | { |
126 | - return function ($object) use ($core) { |
|
126 | + return function($object) use ($core) { |
|
127 | 127 | return $core($object); |
128 | 128 | }; |
129 | 129 | } |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | * @param \Closure $middleware |
136 | 136 | * @return \Closure |
137 | 137 | */ |
138 | - private function createMiddleware(\Closure $nextMiddleware,\Closure $middleware): \Closure |
|
138 | + private function createMiddleware(\Closure $nextMiddleware, \Closure $middleware): \Closure |
|
139 | 139 | { |
140 | - return function ($object) use ($nextMiddleware, $middleware) { |
|
140 | + return function($object) use ($nextMiddleware, $middleware) { |
|
141 | 141 | return $middleware($object, $nextMiddleware); |
142 | 142 | }; |
143 | 143 | } |
@@ -9,7 +9,7 @@ |
||
9 | 9 | * @param int $code |
10 | 10 | * @param \Throwable|null $previous |
11 | 11 | */ |
12 | - public function __construct(string $message = '404 Not Found',int $code = 404, \Throwable $previous = null) |
|
12 | + public function __construct(string $message = '404 Not Found', int $code = 404, \Throwable $previous = null) |
|
13 | 13 | { |
14 | 14 | parent::__construct($message, $code, $previous); |
15 | 15 | } |
@@ -11,5 +11,5 @@ |
||
11 | 11 | * @param Closure $next |
12 | 12 | * @return mixed |
13 | 13 | */ |
14 | - public function run(\Scrawler\Http\Request $request,Closure $next); |
|
14 | + public function run(\Scrawler\Http\Request $request, Closure $next); |
|
15 | 15 | } |
16 | 16 | \ No newline at end of file |