@@ -32,7 +32,7 @@ |
||
32 | 32 | /** |
33 | 33 | * @param string $string |
34 | 34 | * |
35 | - * @return string |
|
35 | + * @return Uuid |
|
36 | 36 | */ |
37 | 37 | public static function fromString(string $string): string |
38 | 38 | { |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class Schedule |
6 | 6 | { |
7 | - /** |
|
8 | - * @param string $name |
|
9 | - */ |
|
10 | - public function command(string $name) |
|
11 | - { |
|
7 | + /** |
|
8 | + * @param string $name |
|
9 | + */ |
|
10 | + public function command(string $name) |
|
11 | + { |
|
12 | 12 | |
13 | - } |
|
13 | + } |
|
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -6,31 +6,31 @@ |
||
6 | 6 | |
7 | 7 | trait OutputAwareTrait |
8 | 8 | { |
9 | - /** |
|
10 | - * @var OutputInterface |
|
11 | - */ |
|
12 | - protected $output; |
|
9 | + /** |
|
10 | + * @var OutputInterface |
|
11 | + */ |
|
12 | + protected $output; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Set an output. |
|
16 | - * |
|
17 | - * @param OutputInterface $output |
|
18 | - * @return $this |
|
19 | - */ |
|
20 | - public function setOutput(OutputInterface $output) |
|
21 | - { |
|
22 | - $this->output = $output; |
|
14 | + /** |
|
15 | + * Set an output. |
|
16 | + * |
|
17 | + * @param OutputInterface $output |
|
18 | + * @return $this |
|
19 | + */ |
|
20 | + public function setOutput(OutputInterface $output) |
|
21 | + { |
|
22 | + $this->output = $output; |
|
23 | 23 | |
24 | - return $this; |
|
25 | - } |
|
24 | + return $this; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Get the output. |
|
29 | - * |
|
30 | - * @return OutputInterface |
|
31 | - */ |
|
32 | - public function getOutput() |
|
33 | - { |
|
34 | - return $this->output; |
|
35 | - } |
|
27 | + /** |
|
28 | + * Get the output. |
|
29 | + * |
|
30 | + * @return OutputInterface |
|
31 | + */ |
|
32 | + public function getOutput() |
|
33 | + { |
|
34 | + return $this->output; |
|
35 | + } |
|
36 | 36 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * @param ServerRequestInterface $request |
28 | 28 | * @param ResponseInterface $response |
29 | 29 | * |
30 | - * @return RequestInterface |
|
30 | + * @return ResponseInterface |
|
31 | 31 | */ |
32 | 32 | public function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
33 | 33 | { |
@@ -46,7 +46,7 @@ |
||
46 | 46 | |
47 | 47 | $route = new RouteCollection($container); |
48 | 48 | |
49 | - $route->map('GET', '/', function (ServerRequestInterface $request, ResponseInterface $response) { |
|
49 | + $route->map('GET', '/', function(ServerRequestInterface $request, ResponseInterface $response) { |
|
50 | 50 | $response->getBody()->write('<h1>Hello, World!</h1>'); |
51 | 51 | |
52 | 52 | return $response; |
@@ -34,25 +34,25 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
36 | 36 | { |
37 | - $container = $this->getContainer(); |
|
37 | + $container = $this->getContainer(); |
|
38 | 38 | $container->share(ServerRequestInterface::class, $request); |
39 | 39 | $container->share(ResponseInterface::class, $response); |
40 | 40 | $container->share('emitter', SapiEmitter::class); |
41 | 41 | |
42 | 42 | foreach ($this->serviceProviders as $serviceProvider) |
43 | - { |
|
44 | - $container->addServiceProvider($serviceProvider); |
|
45 | - } |
|
43 | + { |
|
44 | + $container->addServiceProvider($serviceProvider); |
|
45 | + } |
|
46 | 46 | |
47 | - $route = new RouteCollection($container); |
|
47 | + $route = new RouteCollection($container); |
|
48 | 48 | |
49 | - $route->map('GET', '/', function (ServerRequestInterface $request, ResponseInterface $response) { |
|
50 | - $response->getBody()->write('<h1>Hello, World!</h1>'); |
|
49 | + $route->map('GET', '/', function (ServerRequestInterface $request, ResponseInterface $response) { |
|
50 | + $response->getBody()->write('<h1>Hello, World!</h1>'); |
|
51 | 51 | |
52 | - return $response; |
|
53 | - }); |
|
52 | + return $response; |
|
53 | + }); |
|
54 | 54 | |
55 | - return $route->dispatch($request, $response); |
|
55 | + return $route->dispatch($request, $response); |
|
56 | 56 | |
57 | 57 | // $middlewareResolver = new Resolver(); |
58 | 58 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $middleware = []; |
81 | 81 | |
82 | 82 | foreach ($this->globalMiddleware as $globalMiddleware) { |
83 | - $middleware[] = $this->getContainer()->get($globalMiddleware); |
|
83 | + $middleware[] = $this->getContainer()->get($globalMiddleware); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return $middleware; |
@@ -18,29 +18,29 @@ |
||
18 | 18 | */ |
19 | 19 | public function __construct() |
20 | 20 | { |
21 | - $this->registerExceptionHandler(); |
|
21 | + $this->registerExceptionHandler(); |
|
22 | 22 | |
23 | - $this->createContainer(); |
|
23 | + $this->createContainer(); |
|
24 | 24 | |
25 | - $this->loadEnvironment(); |
|
25 | + $this->loadEnvironment(); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | private function registerExceptionHandler() |
29 | - { |
|
30 | - $handler = new Handler(new DefaultFormatter()); |
|
29 | + { |
|
30 | + $handler = new Handler(new DefaultFormatter()); |
|
31 | 31 | |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | 34 | private function createContainer() |
35 | - { |
|
36 | - $container = new Container; |
|
37 | - $container->delegate(new ReflectionContainer); |
|
38 | - $this->setContainer($container); |
|
39 | - } |
|
40 | - |
|
41 | - private function loadEnvironment() |
|
42 | - { |
|
43 | - $environment = new Dotenv(getcwd() . '/../'); |
|
44 | - $environment->load(); |
|
45 | - } |
|
35 | + { |
|
36 | + $container = new Container; |
|
37 | + $container->delegate(new ReflectionContainer); |
|
38 | + $this->setContainer($container); |
|
39 | + } |
|
40 | + |
|
41 | + private function loadEnvironment() |
|
42 | + { |
|
43 | + $environment = new Dotenv(getcwd() . '/../'); |
|
44 | + $environment->load(); |
|
45 | + } |
|
46 | 46 | } |
@@ -7,13 +7,13 @@ |
||
7 | 7 | class DefaultFormatter implements FormatterInterface |
8 | 8 | { |
9 | 9 | |
10 | - public function format(\Throwable $e): array |
|
11 | - { |
|
12 | - return [ |
|
13 | - 'message' => $e->getMessage(), |
|
14 | - 'file' => $e->getFile(), |
|
15 | - 'line' => $e->getLine(), |
|
16 | - 'trace' => $e->getTrace(), |
|
17 | - ]; |
|
18 | - } |
|
10 | + public function format(\Throwable $e): array |
|
11 | + { |
|
12 | + return [ |
|
13 | + 'message' => $e->getMessage(), |
|
14 | + 'file' => $e->getFile(), |
|
15 | + 'line' => $e->getLine(), |
|
16 | + 'trace' => $e->getTrace(), |
|
17 | + ]; |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -101,6 +101,9 @@ |
||
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | + /** |
|
105 | + * @param integer $statusCode |
|
106 | + */ |
|
104 | 107 | public function sendException($data, $statusCode) |
105 | 108 | { |
106 | 109 | header("HTTP/1.0 " . $statusCode . " Internal Server Error"); |
@@ -34,7 +34,7 @@ |
||
34 | 34 | |
35 | 35 | protected function disablePHPDisplayErrors() |
36 | 36 | { |
37 | - ini_set( 'display_errors', 0 ); |
|
37 | + ini_set('display_errors', 0); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -7,106 +7,106 @@ |
||
7 | 7 | |
8 | 8 | class Handler |
9 | 9 | { |
10 | - const ERROR_HANDLER = 'handleError'; |
|
11 | - const EXCEPTION_HANDLER = 'handleException'; |
|
12 | - const SHUTDOWN_HANDLER = 'handleShutdown'; |
|
13 | - |
|
14 | - /** |
|
15 | - * @var FormatterInterface |
|
16 | - */ |
|
17 | - private $formatter; |
|
18 | - |
|
19 | - /** |
|
20 | - * Handler constructor. |
|
21 | - * |
|
22 | - * @param FormatterInterface $formatter |
|
23 | - */ |
|
24 | - public function __construct(FormatterInterface $formatter) |
|
25 | - { |
|
26 | - $this->formatter = $formatter; |
|
27 | - |
|
28 | - $this->disablePHPDisplayErrors(); |
|
29 | - |
|
30 | - $this->registerErrorHandler(); |
|
31 | - $this->registerExceptionHandler(); |
|
32 | - $this->registerShutdownHandler(); |
|
33 | - } |
|
34 | - |
|
35 | - protected function disablePHPDisplayErrors() |
|
36 | - { |
|
37 | - ini_set( 'display_errors', 0 ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Register the PHP error handler. |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - protected function registerErrorHandler() |
|
46 | - { |
|
47 | - set_error_handler([$this, self::ERROR_HANDLER]); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Register the PHP exception handler. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - protected function registerExceptionHandler() |
|
56 | - { |
|
57 | - set_exception_handler([$this, self::EXCEPTION_HANDLER]); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Register a function for execution on shutdown |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - protected function registerShutdownHandler() |
|
66 | - { |
|
67 | - register_shutdown_function([$this, self::SHUTDOWN_HANDLER]); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param int $level |
|
72 | - * @param string $message |
|
73 | - * @param string $file |
|
74 | - * @param int $line |
|
75 | - * |
|
76 | - * @throws ErrorException |
|
77 | - */ |
|
78 | - public function handleError(int $level, string $message, string $file = '', int $line = 0) |
|
79 | - { |
|
80 | - throw new ErrorException($message, 0, $level, $file, $line); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @param \Throwable $e |
|
85 | - */ |
|
86 | - public function handleException(\Throwable $e) |
|
87 | - { |
|
88 | - $data = json_encode($this->formatter->format($e)); |
|
89 | - $this->sendException($data, 500); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Handle the PHP shutdown event. |
|
94 | - */ |
|
95 | - public function handleShutdown() |
|
96 | - { |
|
97 | - $error = error_get_last(); |
|
98 | - |
|
99 | - if ($error) { |
|
100 | - $this->handleException(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - public function sendException($data, $statusCode) |
|
105 | - { |
|
106 | - header("HTTP/1.0 " . $statusCode . " Internal Server Error"); |
|
107 | - header('Content-Type: application/json; charset=utf-8'); |
|
108 | - echo $data; |
|
109 | - |
|
110 | - return; |
|
111 | - } |
|
10 | + const ERROR_HANDLER = 'handleError'; |
|
11 | + const EXCEPTION_HANDLER = 'handleException'; |
|
12 | + const SHUTDOWN_HANDLER = 'handleShutdown'; |
|
13 | + |
|
14 | + /** |
|
15 | + * @var FormatterInterface |
|
16 | + */ |
|
17 | + private $formatter; |
|
18 | + |
|
19 | + /** |
|
20 | + * Handler constructor. |
|
21 | + * |
|
22 | + * @param FormatterInterface $formatter |
|
23 | + */ |
|
24 | + public function __construct(FormatterInterface $formatter) |
|
25 | + { |
|
26 | + $this->formatter = $formatter; |
|
27 | + |
|
28 | + $this->disablePHPDisplayErrors(); |
|
29 | + |
|
30 | + $this->registerErrorHandler(); |
|
31 | + $this->registerExceptionHandler(); |
|
32 | + $this->registerShutdownHandler(); |
|
33 | + } |
|
34 | + |
|
35 | + protected function disablePHPDisplayErrors() |
|
36 | + { |
|
37 | + ini_set( 'display_errors', 0 ); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Register the PHP error handler. |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + protected function registerErrorHandler() |
|
46 | + { |
|
47 | + set_error_handler([$this, self::ERROR_HANDLER]); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Register the PHP exception handler. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + protected function registerExceptionHandler() |
|
56 | + { |
|
57 | + set_exception_handler([$this, self::EXCEPTION_HANDLER]); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Register a function for execution on shutdown |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + protected function registerShutdownHandler() |
|
66 | + { |
|
67 | + register_shutdown_function([$this, self::SHUTDOWN_HANDLER]); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param int $level |
|
72 | + * @param string $message |
|
73 | + * @param string $file |
|
74 | + * @param int $line |
|
75 | + * |
|
76 | + * @throws ErrorException |
|
77 | + */ |
|
78 | + public function handleError(int $level, string $message, string $file = '', int $line = 0) |
|
79 | + { |
|
80 | + throw new ErrorException($message, 0, $level, $file, $line); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @param \Throwable $e |
|
85 | + */ |
|
86 | + public function handleException(\Throwable $e) |
|
87 | + { |
|
88 | + $data = json_encode($this->formatter->format($e)); |
|
89 | + $this->sendException($data, 500); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Handle the PHP shutdown event. |
|
94 | + */ |
|
95 | + public function handleShutdown() |
|
96 | + { |
|
97 | + $error = error_get_last(); |
|
98 | + |
|
99 | + if ($error) { |
|
100 | + $this->handleException(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + public function sendException($data, $statusCode) |
|
105 | + { |
|
106 | + header("HTTP/1.0 " . $statusCode . " Internal Server Error"); |
|
107 | + header('Content-Type: application/json; charset=utf-8'); |
|
108 | + echo $data; |
|
109 | + |
|
110 | + return; |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -8,18 +8,18 @@ |
||
8 | 8 | class Resolver implements ResolverInterface |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * |
|
13 | - * Converts a middleware queue entry to a callable or an implementation of |
|
14 | - * MiddlewareInterface. |
|
15 | - * |
|
16 | - * @param mixed $entry The middleware queue entry. |
|
17 | - * |
|
18 | - * @return callable|MiddlewareInterface |
|
19 | - * |
|
20 | - */ |
|
21 | - public function __invoke($entry) |
|
22 | - { |
|
23 | - (new $entry)->run(); |
|
24 | - } |
|
11 | + /** |
|
12 | + * |
|
13 | + * Converts a middleware queue entry to a callable or an implementation of |
|
14 | + * MiddlewareInterface. |
|
15 | + * |
|
16 | + * @param mixed $entry The middleware queue entry. |
|
17 | + * |
|
18 | + * @return callable|MiddlewareInterface |
|
19 | + * |
|
20 | + */ |
|
21 | + public function __invoke($entry) |
|
22 | + { |
|
23 | + (new $entry)->run(); |
|
24 | + } |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -4,10 +4,10 @@ |
||
4 | 4 | |
5 | 5 | abstract class Command |
6 | 6 | { |
7 | - /** |
|
8 | - * Execute the console command. |
|
9 | - * |
|
10 | - * @return mixed |
|
11 | - */ |
|
12 | - abstract public function handle(); |
|
7 | + /** |
|
8 | + * Execute the console command. |
|
9 | + * |
|
10 | + * @return mixed |
|
11 | + */ |
|
12 | + abstract public function handle(); |
|
13 | 13 | } |
14 | 14 | \ No newline at end of file |