@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function serialize(array $payload): string |
21 | 21 | { |
22 | - try { |
|
22 | + try{ |
|
23 | 23 | return serialize($payload); |
24 | - } catch (Throwable $e) { |
|
24 | + }catch (Throwable $e){ |
|
25 | 25 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
26 | 26 | } |
27 | 27 | } |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function deserialize(string $payload): array |
33 | 33 | { |
34 | - try { |
|
34 | + try{ |
|
35 | 35 | return (array)unserialize($payload); |
36 | - } catch (Throwable $e) { |
|
36 | + }catch (Throwable $e){ |
|
37 | 37 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
38 | 38 | } |
39 | 39 | } |
@@ -19,9 +19,12 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function serialize(array $payload): string |
21 | 21 | { |
22 | - try { |
|
22 | + try |
|
23 | + { |
|
23 | 24 | return serialize($payload); |
24 | - } catch (Throwable $e) { |
|
25 | + } |
|
26 | + catch (Throwable $e) |
|
27 | + { |
|
25 | 28 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
26 | 29 | } |
27 | 30 | } |
@@ -31,9 +34,12 @@ discard block |
||
31 | 34 | */ |
32 | 35 | public function deserialize(string $payload): array |
33 | 36 | { |
34 | - try { |
|
37 | + try |
|
38 | + { |
|
35 | 39 | return (array)unserialize($payload); |
36 | - } catch (Throwable $e) { |
|
40 | + } |
|
41 | + catch (Throwable $e) |
|
42 | + { |
|
37 | 43 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
38 | 44 | } |
39 | 45 | } |
@@ -20,11 +20,11 @@ |
||
20 | 20 | |
21 | 21 | public function handle(string $name, string $id, array $payload): void |
22 | 22 | { |
23 | - if (!isset($payload['callback'])) { |
|
23 | + if (!isset($payload['callback'])){ |
|
24 | 24 | throw new InvalidArgumentException('Payload `callback` key is required.'); |
25 | 25 | } |
26 | 26 | |
27 | - if (!$payload['callback'] instanceof Closure) { |
|
27 | + if (!$payload['callback'] instanceof Closure){ |
|
28 | 28 | throw new InvalidArgumentException('Payload `callback` key value type should be a closure.'); |
29 | 29 | } |
30 | 30 |
@@ -20,11 +20,13 @@ |
||
20 | 20 | |
21 | 21 | public function handle(string $name, string $id, array $payload): void |
22 | 22 | { |
23 | - if (!isset($payload['callback'])) { |
|
23 | + if (!isset($payload['callback'])) |
|
24 | + { |
|
24 | 25 | throw new InvalidArgumentException('Payload `callback` key is required.'); |
25 | 26 | } |
26 | 27 | |
27 | - if (!$payload['callback'] instanceof Closure) { |
|
28 | + if (!$payload['callback'] instanceof Closure) |
|
29 | + { |
|
28 | 30 | throw new InvalidArgumentException('Payload `callback` key value type should be a closure.'); |
29 | 31 | } |
30 | 32 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | // Replaces alias with real pipeline name |
29 | 29 | $name = $this->config->getAliases()[$name] ?? $name; |
30 | 30 | |
31 | - if (!isset($this->pipelines[$name])) { |
|
31 | + if (!isset($this->pipelines[$name])){ |
|
32 | 32 | $this->pipelines[$name] = $this->resolveConnection($name); |
33 | 33 | } |
34 | 34 | |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | { |
44 | 44 | $config = $this->config->getConnection($name); |
45 | 45 | |
46 | - try { |
|
46 | + try{ |
|
47 | 47 | return $this->factory->make($config['driver'], $config); |
48 | - } catch (ContainerException $e) { |
|
48 | + }catch (ContainerException $e){ |
|
49 | 49 | throw new NotSupportedDriverException( |
50 | 50 | \sprintf( |
51 | 51 | 'Driver `%s` is not supported. Connection `%s` cannot be created. Reason: `%s`', |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | // Replaces alias with real pipeline name |
29 | 29 | $name = $this->config->getAliases()[$name] ?? $name; |
30 | 30 | |
31 | - if (!isset($this->pipelines[$name])) { |
|
31 | + if (!isset($this->pipelines[$name])) |
|
32 | + { |
|
32 | 33 | $this->pipelines[$name] = $this->resolveConnection($name); |
33 | 34 | } |
34 | 35 | |
@@ -43,9 +44,12 @@ discard block |
||
43 | 44 | { |
44 | 45 | $config = $this->config->getConnection($name); |
45 | 46 | |
46 | - try { |
|
47 | + try |
|
48 | + { |
|
47 | 49 | return $this->factory->make($config['driver'], $config); |
48 | - } catch (ContainerException $e) { |
|
50 | + } |
|
51 | + catch (ContainerException $e) |
|
52 | + { |
|
49 | 53 | throw new NotSupportedDriverException( |
50 | 54 | \sprintf( |
51 | 55 | 'Driver `%s` is not supported. Connection `%s` cannot be created. Reason: `%s`', |
@@ -33,12 +33,12 @@ |
||
33 | 33 | */ |
34 | 34 | public function handle(string $name, string $id, array $payload): void |
35 | 35 | { |
36 | - try { |
|
36 | + try{ |
|
37 | 37 | $this->invoker->invoke( |
38 | 38 | [$this, $this->getHandlerMethod()], |
39 | 39 | \array_merge(['payload' => $payload, 'id' => $id], $payload) |
40 | 40 | ); |
41 | - } catch (Throwable $e) { |
|
41 | + }catch (Throwable $e){ |
|
42 | 42 | $message = \sprintf('[%s] %s', \get_class($this), $e->getMessage()); |
43 | 43 | throw new JobException($message, (int)$e->getCode(), $e); |
44 | 44 | } |
@@ -33,12 +33,15 @@ |
||
33 | 33 | */ |
34 | 34 | public function handle(string $name, string $id, array $payload): void |
35 | 35 | { |
36 | - try { |
|
36 | + try |
|
37 | + { |
|
37 | 38 | $this->invoker->invoke( |
38 | 39 | [$this, $this->getHandlerMethod()], |
39 | 40 | \array_merge(['payload' => $payload, 'id' => $id], $payload) |
40 | 41 | ); |
41 | - } catch (Throwable $e) { |
|
42 | + } |
|
43 | + catch (Throwable $e) |
|
44 | + { |
|
42 | 45 | $message = \sprintf('[%s] %s', \get_class($this), $e->getMessage()); |
43 | 46 | throw new JobException($message, (int)$e->getCode(), $e); |
44 | 47 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct( |
26 | 26 | HandlerRegistryInterface $registry, |
27 | 27 | FailedJobHandlerInterface $failedJobHandler |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | $this->registry = $registry; |
30 | 30 | $this->failedJobHandler = $failedJobHandler; |
31 | 31 | } |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | /** @inheritdoc */ |
34 | 34 | public function push(string $name, array $payload = [], OptionsInterface $options = null): string |
35 | 35 | { |
36 | - if ($options !== null && $options->getDelay()) { |
|
36 | + if ($options !== null && $options->getDelay()){ |
|
37 | 37 | sleep($options->getDelay()); |
38 | 38 | } |
39 | 39 | |
40 | 40 | $id = (string)Uuid::uuid4(); |
41 | 41 | |
42 | - try { |
|
42 | + try{ |
|
43 | 43 | $this->registry->getHandler($name)->handle($name, $id, $payload); |
44 | - } catch (Throwable $e) { |
|
44 | + }catch (Throwable $e){ |
|
45 | 45 | $this->failedJobHandler->handle( |
46 | 46 | 'sync', |
47 | 47 | 'default', |
@@ -33,15 +33,19 @@ |
||
33 | 33 | /** @inheritdoc */ |
34 | 34 | public function push(string $name, array $payload = [], OptionsInterface $options = null): string |
35 | 35 | { |
36 | - if ($options !== null && $options->getDelay()) { |
|
36 | + if ($options !== null && $options->getDelay()) |
|
37 | + { |
|
37 | 38 | sleep($options->getDelay()); |
38 | 39 | } |
39 | 40 | |
40 | 41 | $id = (string)Uuid::uuid4(); |
41 | 42 | |
42 | - try { |
|
43 | + try |
|
44 | + { |
|
43 | 45 | $this->registry->getHandler($name)->handle($name, $id, $payload); |
44 | - } catch (Throwable $e) { |
|
46 | + } |
|
47 | + catch (Throwable $e) |
|
48 | + { |
|
45 | 49 | $this->failedJobHandler->handle( |
46 | 50 | 'sync', |
47 | 51 | 'default', |
@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | |
28 | 28 | public function createInjection(ReflectionClass $class, string $context = null): QueueInterface |
29 | 29 | { |
30 | - try { |
|
31 | - if ($context === null) { |
|
30 | + try{ |
|
31 | + if ($context === null){ |
|
32 | 32 | $connection = $this->queueManager->getConnection(); |
33 | - } else { |
|
33 | + }else{ |
|
34 | 34 | // Get Queue by context |
35 | - try { |
|
35 | + try{ |
|
36 | 36 | $connection = $this->queueManager->getConnection($context); |
37 | - } catch (InvalidArgumentException $e) { |
|
37 | + }catch (InvalidArgumentException $e){ |
|
38 | 38 | // Case when context doesn't match to configured connections |
39 | 39 | return $this->queueManager->getConnection(); |
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | 43 | $this->matchType($class, $context, $connection); |
44 | - } catch (Throwable $e) { |
|
44 | + }catch (Throwable $e){ |
|
45 | 45 | throw new ContainerException(sprintf("Can't inject the required queue. %s", $e->getMessage()), 0, $e); |
46 | 46 | } |
47 | 47 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | private function matchType(ReflectionClass $class, ?string $context, QueueInterface $connection): void |
57 | 57 | { |
58 | 58 | $className = $class->getName(); |
59 | - if ($className !== QueueInterface::class && !$connection instanceof $className) { |
|
59 | + if ($className !== QueueInterface::class && !$connection instanceof $className){ |
|
60 | 60 | throw new RuntimeException( |
61 | 61 | \sprintf( |
62 | 62 | "The queue obtained by the context `%s` doesn't match the type `%s`.", |
@@ -27,21 +27,30 @@ discard block |
||
27 | 27 | |
28 | 28 | public function createInjection(ReflectionClass $class, string $context = null): QueueInterface |
29 | 29 | { |
30 | - try { |
|
31 | - if ($context === null) { |
|
30 | + try |
|
31 | + { |
|
32 | + if ($context === null) |
|
33 | + { |
|
32 | 34 | $connection = $this->queueManager->getConnection(); |
33 | - } else { |
|
35 | + } |
|
36 | + else |
|
37 | + { |
|
34 | 38 | // Get Queue by context |
35 | - try { |
|
39 | + try |
|
40 | + { |
|
36 | 41 | $connection = $this->queueManager->getConnection($context); |
37 | - } catch (InvalidArgumentException $e) { |
|
42 | + } |
|
43 | + catch (InvalidArgumentException $e) |
|
44 | + { |
|
38 | 45 | // Case when context doesn't match to configured connections |
39 | 46 | return $this->queueManager->getConnection(); |
40 | 47 | } |
41 | 48 | } |
42 | 49 | |
43 | 50 | $this->matchType($class, $context, $connection); |
44 | - } catch (Throwable $e) { |
|
51 | + } |
|
52 | + catch (Throwable $e) |
|
53 | + { |
|
45 | 54 | throw new ContainerException(sprintf("Can't inject the required queue. %s", $e->getMessage()), 0, $e); |
46 | 55 | } |
47 | 56 | |
@@ -56,7 +65,8 @@ discard block |
||
56 | 65 | private function matchType(ReflectionClass $class, ?string $context, QueueInterface $connection): void |
57 | 66 | { |
58 | 67 | $className = $class->getName(); |
59 | - if ($className !== QueueInterface::class && !$connection instanceof $className) { |
|
68 | + if ($className !== QueueInterface::class && !$connection instanceof $className) |
|
69 | + { |
|
60 | 70 | throw new RuntimeException( |
61 | 71 | \sprintf( |
62 | 72 | "The queue obtained by the context `%s` doesn't match the type `%s`.", |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | { |
42 | 42 | $filename = $this->getFilename($section); |
43 | 43 | |
44 | - if (!file_exists($filename)) { |
|
44 | + if (!file_exists($filename)){ |
|
45 | 45 | return null; |
46 | 46 | } |
47 | 47 | |
48 | - try { |
|
48 | + try{ |
|
49 | 49 | return include($filename); |
50 | - } catch (Throwable $e) { |
|
50 | + }catch (Throwable $e){ |
|
51 | 51 | return null; |
52 | 52 | } |
53 | 53 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | $this->files->write( |
61 | 61 | $this->getFilename($section), |
62 | - '<?php return ' . var_export($data, true) . ';', |
|
62 | + '<?php return '.var_export($data, true).';', |
|
63 | 63 | FilesInterface::RUNTIME, |
64 | 64 | true |
65 | 65 | ); |
@@ -41,13 +41,17 @@ |
||
41 | 41 | { |
42 | 42 | $filename = $this->getFilename($section); |
43 | 43 | |
44 | - if (!file_exists($filename)) { |
|
44 | + if (!file_exists($filename)) |
|
45 | + { |
|
45 | 46 | return null; |
46 | 47 | } |
47 | 48 | |
48 | - try { |
|
49 | + try |
|
50 | + { |
|
49 | 51 | return include($filename); |
50 | - } catch (Throwable $e) { |
|
52 | + } |
|
53 | + catch (Throwable $e) |
|
54 | + { |
|
51 | 55 | return null; |
52 | 56 | } |
53 | 57 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public static function handleShutdown(): void |
54 | 54 | { |
55 | - if (!empty($error = error_get_last())) { |
|
55 | + if (!empty($error = error_get_last())){ |
|
56 | 56 | self::handleException( |
57 | 57 | new FatalException( |
58 | 58 | $error['message'], |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public static function handleError($code, $message, $filename = '', $line = 0): void |
79 | 79 | { |
80 | - if (!(error_reporting() & $code)) { |
|
80 | + if (!(error_reporting() & $code)){ |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public static function handleException(Throwable $e): void |
91 | 91 | { |
92 | - if (self::$output === null) { |
|
92 | + if (self::$output === null){ |
|
93 | 93 | self::$output = defined('STDERR') ? STDERR : fopen('php://stderr', 'w+'); |
94 | 94 | } |
95 | 95 | |
96 | - if (php_sapi_name() == 'cli') { |
|
96 | + if (php_sapi_name() == 'cli'){ |
|
97 | 97 | $handler = new ConsoleHandler(self::$output); |
98 | - } else { |
|
98 | + }else{ |
|
99 | 99 | $handler = new HtmlHandler(HtmlHandler::INVERTED); |
100 | 100 | } |
101 | 101 |
@@ -52,7 +52,8 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public static function handleShutdown(): void |
54 | 54 | { |
55 | - if (!empty($error = error_get_last())) { |
|
55 | + if (!empty($error = error_get_last())) |
|
56 | + { |
|
56 | 57 | self::handleException( |
57 | 58 | new FatalException( |
58 | 59 | $error['message'], |
@@ -77,7 +78,8 @@ discard block |
||
77 | 78 | */ |
78 | 79 | public static function handleError($code, $message, $filename = '', $line = 0): void |
79 | 80 | { |
80 | - if (!(error_reporting() & $code)) { |
|
81 | + if (!(error_reporting() & $code)) |
|
82 | + { |
|
81 | 83 | return; |
82 | 84 | } |
83 | 85 | |
@@ -89,13 +91,17 @@ discard block |
||
89 | 91 | */ |
90 | 92 | public static function handleException(Throwable $e): void |
91 | 93 | { |
92 | - if (self::$output === null) { |
|
94 | + if (self::$output === null) |
|
95 | + { |
|
93 | 96 | self::$output = defined('STDERR') ? STDERR : fopen('php://stderr', 'w+'); |
94 | 97 | } |
95 | 98 | |
96 | - if (php_sapi_name() == 'cli') { |
|
99 | + if (php_sapi_name() == 'cli') |
|
100 | + { |
|
97 | 101 | $handler = new ConsoleHandler(self::$output); |
98 | - } else { |
|
102 | + } |
|
103 | + else |
|
104 | + { |
|
99 | 105 | $handler = new HtmlHandler(HtmlHandler::INVERTED); |
100 | 106 | } |
101 | 107 |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | array $directories, |
115 | 115 | bool $handleErrors = true |
116 | 116 | ): self { |
117 | - if ($handleErrors) { |
|
117 | + if ($handleErrors){ |
|
118 | 118 | ExceptionHandler::register(); |
119 | 119 | } |
120 | 120 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $environment ??= new Environment(); |
138 | 138 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
139 | 139 | |
140 | - try { |
|
140 | + try{ |
|
141 | 141 | // will protect any against env overwrite action |
142 | 142 | $this->container->runScope( |
143 | 143 | [EnvironmentInterface::class => $environment], |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $this->bootstrap(); |
147 | 147 | } |
148 | 148 | ); |
149 | - } catch (Throwable $e) { |
|
149 | + }catch (Throwable $e){ |
|
150 | 150 | ExceptionHandler::handleException($e); |
151 | 151 | |
152 | 152 | return null; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function starting(Closure ...$callbacks): void |
168 | 168 | { |
169 | - foreach ($callbacks as $callback) { |
|
169 | + foreach ($callbacks as $callback){ |
|
170 | 170 | $this->startingCallbacks[] = $callback; |
171 | 171 | } |
172 | 172 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function started(Closure ...$callbacks): void |
184 | 184 | { |
185 | - foreach ($callbacks as $callback) { |
|
185 | + foreach ($callbacks as $callback){ |
|
186 | 186 | $this->startedCallbacks[] = $callback; |
187 | 187 | } |
188 | 188 | } |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function serve() |
208 | 208 | { |
209 | - foreach ($this->dispatchers as $dispatcher) { |
|
210 | - if ($dispatcher->canServe()) { |
|
209 | + foreach ($this->dispatchers as $dispatcher){ |
|
210 | + if ($dispatcher->canServe()){ |
|
211 | 211 | return $this->container->runScope( |
212 | 212 | [DispatcherInterface::class => $dispatcher], |
213 | 213 | [$dispatcher, 'serve'] |
@@ -261,13 +261,13 @@ discard block |
||
261 | 261 | */ |
262 | 262 | private function fireCallbacks(array &$callbacks): void |
263 | 263 | { |
264 | - if ($callbacks === []) { |
|
264 | + if ($callbacks === []){ |
|
265 | 265 | return; |
266 | 266 | } |
267 | 267 | |
268 | - do { |
|
268 | + do{ |
|
269 | 269 | $this->container->invoke(\current($callbacks)); |
270 | - } while (\next($callbacks)); |
|
270 | + }while (\next($callbacks)); |
|
271 | 271 | |
272 | 272 | $callbacks = []; |
273 | 273 | } |
@@ -114,7 +114,8 @@ discard block |
||
114 | 114 | array $directories, |
115 | 115 | bool $handleErrors = true |
116 | 116 | ): self { |
117 | - if ($handleErrors) { |
|
117 | + if ($handleErrors) |
|
118 | + { |
|
118 | 119 | ExceptionHandler::register(); |
119 | 120 | } |
120 | 121 | |
@@ -137,7 +138,8 @@ discard block |
||
137 | 138 | $environment ??= new Environment(); |
138 | 139 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
139 | 140 | |
140 | - try { |
|
141 | + try |
|
142 | + { |
|
141 | 143 | // will protect any against env overwrite action |
142 | 144 | $this->container->runScope( |
143 | 145 | [EnvironmentInterface::class => $environment], |
@@ -146,7 +148,9 @@ discard block |
||
146 | 148 | $this->bootstrap(); |
147 | 149 | } |
148 | 150 | ); |
149 | - } catch (Throwable $e) { |
|
151 | + } |
|
152 | + catch (Throwable $e) |
|
153 | + { |
|
150 | 154 | ExceptionHandler::handleException($e); |
151 | 155 | |
152 | 156 | return null; |
@@ -166,7 +170,8 @@ discard block |
||
166 | 170 | */ |
167 | 171 | public function starting(Closure ...$callbacks): void |
168 | 172 | { |
169 | - foreach ($callbacks as $callback) { |
|
173 | + foreach ($callbacks as $callback) |
|
174 | + { |
|
170 | 175 | $this->startingCallbacks[] = $callback; |
171 | 176 | } |
172 | 177 | } |
@@ -182,7 +187,8 @@ discard block |
||
182 | 187 | */ |
183 | 188 | public function started(Closure ...$callbacks): void |
184 | 189 | { |
185 | - foreach ($callbacks as $callback) { |
|
190 | + foreach ($callbacks as $callback) |
|
191 | + { |
|
186 | 192 | $this->startedCallbacks[] = $callback; |
187 | 193 | } |
188 | 194 | } |
@@ -206,8 +212,10 @@ discard block |
||
206 | 212 | */ |
207 | 213 | public function serve() |
208 | 214 | { |
209 | - foreach ($this->dispatchers as $dispatcher) { |
|
210 | - if ($dispatcher->canServe()) { |
|
215 | + foreach ($this->dispatchers as $dispatcher) |
|
216 | + { |
|
217 | + if ($dispatcher->canServe()) |
|
218 | + { |
|
211 | 219 | return $this->container->runScope( |
212 | 220 | [DispatcherInterface::class => $dispatcher], |
213 | 221 | [$dispatcher, 'serve'] |
@@ -261,11 +269,13 @@ discard block |
||
261 | 269 | */ |
262 | 270 | private function fireCallbacks(array &$callbacks): void |
263 | 271 | { |
264 | - if ($callbacks === []) { |
|
272 | + if ($callbacks === []) |
|
273 | + { |
|
265 | 274 | return; |
266 | 275 | } |
267 | 276 | |
268 | - do { |
|
277 | + do |
|
278 | + { |
|
269 | 279 | $this->container->invoke(\current($callbacks)); |
270 | 280 | } while (\next($callbacks)); |
271 | 281 |