@@ -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 |
@@ -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 |
@@ -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); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | $middlewares = array_reverse($this->middlewares); |
106 | 106 | |
107 | 107 | |
108 | - $completePipeline = array_reduce($middlewares, function ($nextMiddleware, $middleware) { |
|
108 | + $completePipeline = array_reduce($middlewares, function($nextMiddleware, $middleware) { |
|
109 | 109 | return $this->createMiddleware($nextMiddleware, $middleware); |
110 | 110 | }, $coreFunction); |
111 | 111 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | private function createCoreFunction(\Closure $core) |
124 | 124 | { |
125 | - return function ($object) use ($core) { |
|
125 | + return function($object) use ($core) { |
|
126 | 126 | return $core($object); |
127 | 127 | }; |
128 | 128 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | private function createMiddleware(\Closure $nextMiddleware, \Closure $middleware): \Closure |
138 | 138 | { |
139 | - return function ($object) use ($nextMiddleware, $middleware) { |
|
139 | + return function($object) use ($nextMiddleware, $middleware) { |
|
140 | 140 | return $middleware($object, $nextMiddleware); |
141 | 141 | }; |
142 | 142 | } |