@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @see https://github.com/symplify/symplify/issues/2061 |
19 | 19 | */ |
20 | -register_shutdown_function(static function () { |
|
21 | - $dest = json_decode(file_get_contents(__DIR__ . '/composer.json'), true); |
|
20 | +register_shutdown_function(static function (){ |
|
21 | + $dest = json_decode(file_get_contents(__DIR__.'/composer.json'), true); |
|
22 | 22 | |
23 | 23 | $result = [ |
24 | 24 | 'name' => 'spiral/framework', |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | $json = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
55 | 55 | |
56 | - file_put_contents(__DIR__ . '/composer.json', $json . "\n"); |
|
56 | + file_put_contents(__DIR__.'/composer.json', $json."\n"); |
|
57 | 57 | }); |
58 | 58 | |
59 | 59 |
@@ -17,7 +17,8 @@ |
||
17 | 17 | * |
18 | 18 | * @see https://github.com/symplify/symplify/issues/2061 |
19 | 19 | */ |
20 | -register_shutdown_function(static function () { |
|
20 | +register_shutdown_function(static function () |
|
21 | +{ |
|
21 | 22 | $dest = json_decode(file_get_contents(__DIR__ . '/composer.json'), true); |
22 | 23 | |
23 | 24 | $result = [ |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function boot(DirectoriesInterface $dirs, EnvironmentInterface $env) |
26 | 26 | { |
27 | - $dotenvPath = $env->get('DOTENV_PATH', $dirs->get('root') . '.env'); |
|
27 | + $dotenvPath = $env->get('DOTENV_PATH', $dirs->get('root').'.env'); |
|
28 | 28 | |
29 | - if (!file_exists($dotenvPath)) { |
|
29 | + if (!file_exists($dotenvPath)){ |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | ) |
37 | 37 | ->load(); |
38 | 38 | |
39 | - foreach ($dotenv as $key => $value) { |
|
39 | + foreach ($dotenv as $key => $value){ |
|
40 | 40 | $env->set($key, $value); |
41 | 41 | } |
42 | 42 | } |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | { |
27 | 27 | $dotenvPath = $env->get('DOTENV_PATH', $dirs->get('root') . '.env'); |
28 | 28 | |
29 | - if (!file_exists($dotenvPath)) { |
|
29 | + if (!file_exists($dotenvPath)) |
|
30 | + { |
|
30 | 31 | return; |
31 | 32 | } |
32 | 33 | |
@@ -36,7 +37,8 @@ discard block |
||
36 | 37 | ) |
37 | 38 | ->load(); |
38 | 39 | |
39 | - foreach ($dotenv as $key => $value) { |
|
40 | + foreach ($dotenv as $key => $value) |
|
41 | + { |
|
40 | 42 | $env->set($key, $value); |
41 | 43 | } |
42 | 44 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | PSR7WorkerInterface $worker, |
59 | 59 | ContainerInterface $container, |
60 | 60 | FinalizerInterface $finalizer |
61 | - ) { |
|
61 | + ){ |
|
62 | 62 | $this->env = $env; |
63 | 63 | $this->worker = $worker; |
64 | 64 | $this->container = $container; |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | { |
81 | 81 | /** @var Http $http */ |
82 | 82 | $http = $this->container->get(Http::class); |
83 | - while ($request = $this->worker->waitRequest()) { |
|
84 | - try { |
|
83 | + while ($request = $this->worker->waitRequest()){ |
|
84 | + try{ |
|
85 | 85 | $response = $http->handle($request); |
86 | 86 | |
87 | 87 | $this->worker->respond($response); |
88 | - } catch (\Throwable $e) { |
|
88 | + }catch (\Throwable $e){ |
|
89 | 89 | $this->worker->respond($this->errorToResponse($e)); |
90 | - } finally { |
|
90 | + }finally{ |
|
91 | 91 | $this->finalizer->finalize(false); |
92 | 92 | } |
93 | 93 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | { |
102 | 102 | $handler = new HtmlHandler(); |
103 | 103 | |
104 | - try { |
|
104 | + try{ |
|
105 | 105 | /** @var SnapshotInterface $snapshot */ |
106 | 106 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
107 | 107 | \file_put_contents('php://stderr', $snapshot->getMessage()); |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | // on demand |
110 | 110 | $state = $this->container->get(StateInterface::class); |
111 | 111 | |
112 | - if ($state !== null) { |
|
112 | + if ($state !== null){ |
|
113 | 113 | $handler = $handler->withState($state); |
114 | 114 | } |
115 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
115 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
116 | 116 | \file_put_contents('php://stderr', (string)$e); |
117 | 117 | } |
118 | 118 |
@@ -80,14 +80,20 @@ discard block |
||
80 | 80 | { |
81 | 81 | /** @var Http $http */ |
82 | 82 | $http = $this->container->get(Http::class); |
83 | - while ($request = $this->worker->waitRequest()) { |
|
84 | - try { |
|
83 | + while ($request = $this->worker->waitRequest()) |
|
84 | + { |
|
85 | + try |
|
86 | + { |
|
85 | 87 | $response = $http->handle($request); |
86 | 88 | |
87 | 89 | $this->worker->respond($response); |
88 | - } catch (\Throwable $e) { |
|
90 | + } |
|
91 | + catch (\Throwable $e) |
|
92 | + { |
|
89 | 93 | $this->worker->respond($this->errorToResponse($e)); |
90 | - } finally { |
|
94 | + } |
|
95 | + finally |
|
96 | + { |
|
91 | 97 | $this->finalizer->finalize(false); |
92 | 98 | } |
93 | 99 | } |
@@ -101,7 +107,8 @@ discard block |
||
101 | 107 | { |
102 | 108 | $handler = new HtmlHandler(); |
103 | 109 | |
104 | - try { |
|
110 | + try |
|
111 | + { |
|
105 | 112 | /** @var SnapshotInterface $snapshot */ |
106 | 113 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
107 | 114 | \file_put_contents('php://stderr', $snapshot->getMessage()); |
@@ -109,10 +116,13 @@ discard block |
||
109 | 116 | // on demand |
110 | 117 | $state = $this->container->get(StateInterface::class); |
111 | 118 | |
112 | - if ($state !== null) { |
|
119 | + if ($state !== null) |
|
120 | + { |
|
113 | 121 | $handler = $handler->withState($state); |
114 | 122 | } |
115 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
123 | + } |
|
124 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
125 | + { |
|
116 | 126 | \file_put_contents('php://stderr', (string)$e); |
117 | 127 | } |
118 | 128 |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function push(string $jobType, array $payload = [], Options $options = null): string |
55 | 55 | { |
56 | - try { |
|
57 | - return $this->rpc->call(self::RR_SERVICE . '.Push', [ |
|
56 | + try{ |
|
57 | + return $this->rpc->call(self::RR_SERVICE.'.Push', [ |
|
58 | 58 | 'job' => $this->jobName($jobType), |
59 | 59 | 'payload' => $this->serialize($jobType, $payload), |
60 | 60 | 'options' => $options ?? new Options(), |
61 | 61 | ]); |
62 | - } catch (RoadRunnerException | \Throwable $e) { |
|
62 | + }catch (RoadRunnerException | \Throwable $e){ |
|
63 | 63 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
64 | 64 | } |
65 | 65 | } |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function pushAsync(string $jobType, array $payload = [], Options $options = null): bool |
78 | 78 | { |
79 | - try { |
|
80 | - return $this->rpc->call(self::RR_SERVICE . '.PushAsync', [ |
|
79 | + try{ |
|
80 | + return $this->rpc->call(self::RR_SERVICE.'.PushAsync', [ |
|
81 | 81 | 'job' => $this->jobName($jobType), |
82 | 82 | 'payload' => $this->serialize($jobType, $payload), |
83 | 83 | 'options' => $options ?? new Options(), |
84 | 84 | ]); |
85 | - } catch (RoadRunnerException | \Throwable $e) { |
|
85 | + }catch (RoadRunnerException | \Throwable $e){ |
|
86 | 86 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
87 | 87 | } |
88 | 88 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | private function jobName(string $job): string |
95 | 95 | { |
96 | 96 | $names = explode('\\', $job); |
97 | - $names = array_map(function (string $value) { |
|
97 | + $names = array_map(function (string $value){ |
|
98 | 98 | return $this->inflector->camelize($value); |
99 | 99 | }, $names); |
100 | 100 |
@@ -53,13 +53,16 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function push(string $jobType, array $payload = [], Options $options = null): string |
55 | 55 | { |
56 | - try { |
|
56 | + try |
|
57 | + { |
|
57 | 58 | return $this->rpc->call(self::RR_SERVICE . '.Push', [ |
58 | 59 | 'job' => $this->jobName($jobType), |
59 | 60 | 'payload' => $this->serialize($jobType, $payload), |
60 | 61 | 'options' => $options ?? new Options(), |
61 | 62 | ]); |
62 | - } catch (RoadRunnerException | \Throwable $e) { |
|
63 | + } |
|
64 | + catch (RoadRunnerException | \Throwable $e) |
|
65 | + { |
|
63 | 66 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
64 | 67 | } |
65 | 68 | } |
@@ -76,13 +79,16 @@ discard block |
||
76 | 79 | */ |
77 | 80 | public function pushAsync(string $jobType, array $payload = [], Options $options = null): bool |
78 | 81 | { |
79 | - try { |
|
82 | + try |
|
83 | + { |
|
80 | 84 | return $this->rpc->call(self::RR_SERVICE . '.PushAsync', [ |
81 | 85 | 'job' => $this->jobName($jobType), |
82 | 86 | 'payload' => $this->serialize($jobType, $payload), |
83 | 87 | 'options' => $options ?? new Options(), |
84 | 88 | ]); |
85 | - } catch (RoadRunnerException | \Throwable $e) { |
|
89 | + } |
|
90 | + catch (RoadRunnerException | \Throwable $e) |
|
91 | + { |
|
86 | 92 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
87 | 93 | } |
88 | 94 | } |
@@ -94,7 +100,8 @@ discard block |
||
94 | 100 | private function jobName(string $job): string |
95 | 101 | { |
96 | 102 | $names = explode('\\', $job); |
97 | - $names = array_map(function (string $value) { |
|
103 | + $names = array_map(function (string $value) |
|
104 | + { |
|
98 | 105 | return $this->inflector->camelize($value); |
99 | 106 | }, $names); |
100 | 107 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | ContainerInterface $container, |
40 | 40 | FinalizerInterface $finalizer, |
41 | 41 | EnvironmentInterface $env |
42 | - ) { |
|
42 | + ){ |
|
43 | 43 | $this->env = $env; |
44 | 44 | $this->container = $container; |
45 | 45 | $this->finalizer = $finalizer; |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | /** @var ConsumerInterface $consumer */ |
62 | 62 | $consumer = $this->container->get(ConsumerInterface::class); |
63 | 63 | |
64 | - while ($task = $consumer->waitTask()) { |
|
65 | - try { |
|
64 | + while ($task = $consumer->waitTask()){ |
|
65 | + try{ |
|
66 | 66 | $instance = $this->container->get($task->getName()); |
67 | 67 | |
68 | - if (!$instance instanceof HandlerInterface) { |
|
68 | + if (!$instance instanceof HandlerInterface){ |
|
69 | 69 | throw new \LogicException( |
70 | 70 | \sprintf('Job should be an instance %s', HandlerInterface::class) |
71 | 71 | ); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | $instance->handle($task->getName(), $task->getId(), $task->getPayload()); |
75 | 75 | $task->complete(); |
76 | - } catch (\Throwable $e) { |
|
76 | + }catch (\Throwable $e){ |
|
77 | 77 | $this->handleException($e); |
78 | 78 | $task->fail($e); |
79 | 79 | } |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | */ |
88 | 88 | protected function handleException(\Throwable $e): void |
89 | 89 | { |
90 | - try { |
|
90 | + try{ |
|
91 | 91 | $this->container->get(SnapshotterInterface::class)->register($e); |
92 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
92 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
93 | 93 | // no need to notify when unable to register an exception |
94 | 94 | } |
95 | 95 | } |
@@ -61,11 +61,14 @@ discard block |
||
61 | 61 | /** @var ConsumerInterface $consumer */ |
62 | 62 | $consumer = $this->container->get(ConsumerInterface::class); |
63 | 63 | |
64 | - while ($task = $consumer->waitTask()) { |
|
65 | - try { |
|
64 | + while ($task = $consumer->waitTask()) |
|
65 | + { |
|
66 | + try |
|
67 | + { |
|
66 | 68 | $instance = $this->container->get($task->getName()); |
67 | 69 | |
68 | - if (!$instance instanceof HandlerInterface) { |
|
70 | + if (!$instance instanceof HandlerInterface) |
|
71 | + { |
|
69 | 72 | throw new \LogicException( |
70 | 73 | \sprintf('Job should be an instance %s', HandlerInterface::class) |
71 | 74 | ); |
@@ -73,7 +76,9 @@ discard block |
||
73 | 76 | |
74 | 77 | $instance->handle($task->getName(), $task->getId(), $task->getPayload()); |
75 | 78 | $task->complete(); |
76 | - } catch (\Throwable $e) { |
|
79 | + } |
|
80 | + catch (\Throwable $e) |
|
81 | + { |
|
77 | 82 | $this->handleException($e); |
78 | 83 | $task->fail($e); |
79 | 84 | } |
@@ -87,9 +92,12 @@ discard block |
||
87 | 92 | */ |
88 | 93 | protected function handleException(\Throwable $e): void |
89 | 94 | { |
90 | - try { |
|
95 | + try |
|
96 | + { |
|
91 | 97 | $this->container->get(SnapshotterInterface::class)->register($e); |
92 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
98 | + } |
|
99 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
100 | + { |
|
93 | 101 | // no need to notify when unable to register an exception |
94 | 102 | } |
95 | 103 | } |
@@ -128,7 +128,7 @@ |
||
128 | 128 | */ |
129 | 129 | private function getContext(?OptionsInterface $options): QueueInterface |
130 | 130 | { |
131 | - if ($options instanceof Options && $options->getPipeline() !== null) { |
|
131 | + if ($options instanceof Options && $options->getPipeline() !== null){ |
|
132 | 132 | $original = $this->jobs->connect($options->getPipeline()); |
133 | 133 | |
134 | 134 | return new self($this->jobs, $original); |
@@ -128,7 +128,8 @@ |
||
128 | 128 | */ |
129 | 129 | private function getContext(?OptionsInterface $options): QueueInterface |
130 | 130 | { |
131 | - if ($options instanceof Options && $options->getPipeline() !== null) { |
|
131 | + if ($options instanceof Options && $options->getPipeline() !== null) |
|
132 | + { |
|
132 | 133 | $original = $this->jobs->connect($options->getPipeline()); |
133 | 134 | |
134 | 135 | return new self($this->jobs, $original); |
@@ -103,6 +103,4 @@ |
||
103 | 103 | $options = new self(); |
104 | 104 | $options->base = $options->base->withDelay($delay); |
105 | 105 | |
106 | - return $options; |
|
107 | - } |
|
108 | -} |
|
106 | + return $options |
|
109 | 107 | \ No newline at end of file |
@@ -103,6 +103,4 @@ |
||
103 | 103 | $options = new self(); |
104 | 104 | $options->base = $options->base->withDelay($delay); |
105 | 105 | |
106 | - return $options; |
|
107 | - } |
|
108 | -} |
|
106 | + return $options |
|
109 | 107 | \ No newline at end of file |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | public function jsonSerialize(): array |
85 | 85 | { |
86 | 86 | return [ |
87 | -<<<<<<< HEAD |
|
87 | +<< << <<< HEAD |
|
88 | 88 | 'delay' => $this->base->delay ?: null, |
89 | 89 | 'pipeline' => $this->pipeline |
90 | 90 | ======= |
@@ -103,6 +103,4 @@ discard block |
||
103 | 103 | $options = new self(); |
104 | 104 | $options->base = $options->base->withDelay($delay); |
105 | 105 | |
106 | - return $options; |
|
107 | - } |
|
108 | -} |
|
106 | + return $options |
|
109 | 107 | \ No newline at end of file |
@@ -103,6 +103,4 @@ |
||
103 | 103 | $options = new self(); |
104 | 104 | $options->base = $options->base->withDelay($delay); |
105 | 105 | |
106 | - return $options; |
|
107 | - } |
|
108 | -} |
|
106 | + return $options |
|
109 | 107 | \ No newline at end of file |
@@ -103,6 +103,4 @@ |
||
103 | 103 | $options = new self(); |
104 | 104 | $options->base = $options->base->withDelay($delay); |
105 | 105 | |
106 | - return $options; |
|
107 | - } |
|
108 | -} |
|
106 | + return $options |
|
109 | 107 | \ No newline at end of file |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | { |
41 | 41 | $kernel->addDispatcher($jobs); |
42 | 42 | |
43 | - if (!$container->has(SerializerInterface::class)) { |
|
43 | + if (!$container->has(SerializerInterface::class)){ |
|
44 | 44 | $this->registerJobsSerializer($container); |
45 | 45 | } |
46 | 46 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | private function registerJobsSerializer(Container $container): void |
81 | 81 | { |
82 | - $container->bindSingleton(SerializerInterface::class, static function () { |
|
82 | + $container->bindSingleton(SerializerInterface::class, static function (){ |
|
83 | 83 | return new DefaultSerializer(); |
84 | 84 | }); |
85 | 85 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | private function registerQueue(Container $container): void |
135 | 135 | { |
136 | 136 | $container->bindSingleton(Queue::class, static function (JobsInterface $jobs): Queue { |
137 | - foreach ($jobs as $queue) { |
|
137 | + foreach ($jobs as $queue){ |
|
138 | 138 | return $queue; |
139 | 139 | } |
140 | 140 |
@@ -40,7 +40,8 @@ discard block |
||
40 | 40 | { |
41 | 41 | $kernel->addDispatcher($jobs); |
42 | 42 | |
43 | - if (!$container->has(SerializerInterface::class)) { |
|
43 | + if (!$container->has(SerializerInterface::class)) |
|
44 | + { |
|
44 | 45 | $this->registerJobsSerializer($container); |
45 | 46 | } |
46 | 47 | |
@@ -79,7 +80,8 @@ discard block |
||
79 | 80 | */ |
80 | 81 | private function registerJobsSerializer(Container $container): void |
81 | 82 | { |
82 | - $container->bindSingleton(SerializerInterface::class, static function () { |
|
83 | + $container->bindSingleton(SerializerInterface::class, static function () |
|
84 | + { |
|
83 | 85 | return new DefaultSerializer(); |
84 | 86 | }); |
85 | 87 | } |
@@ -134,7 +136,8 @@ discard block |
||
134 | 136 | private function registerQueue(Container $container): void |
135 | 137 | { |
136 | 138 | $container->bindSingleton(Queue::class, static function (JobsInterface $jobs): Queue { |
137 | - foreach ($jobs as $queue) { |
|
139 | + foreach ($jobs as $queue) |
|
140 | + { |
|
138 | 141 | return $queue; |
139 | 142 | } |
140 | 143 |
@@ -40,10 +40,10 @@ |
||
40 | 40 | $method = new \ReflectionMethod($this, $this->getHandlerMethod()); |
41 | 41 | $method->setAccessible(true); |
42 | 42 | |
43 | - try { |
|
43 | + try{ |
|
44 | 44 | $parameters = \array_merge(['payload' => $payload, 'id' => $id], $payload); |
45 | 45 | $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); |
46 | - } catch (\Throwable $e) { |
|
46 | + }catch (\Throwable $e){ |
|
47 | 47 | $message = \sprintf('[%s] %s', \get_class($this), $e->getMessage()); |
48 | 48 | throw new JobException($message, (int)$e->getCode(), $e); |
49 | 49 | } |
@@ -40,10 +40,13 @@ |
||
40 | 40 | $method = new \ReflectionMethod($this, $this->getHandlerMethod()); |
41 | 41 | $method->setAccessible(true); |
42 | 42 | |
43 | - try { |
|
43 | + try |
|
44 | + { |
|
44 | 45 | $parameters = \array_merge(['payload' => $payload, 'id' => $id], $payload); |
45 | 46 | $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); |
46 | - } catch (\Throwable $e) { |
|
47 | + } |
|
48 | + catch (\Throwable $e) |
|
49 | + { |
|
47 | 50 | $message = \sprintf('[%s] %s', \get_class($this), $e->getMessage()); |
48 | 51 | throw new JobException($message, (int)$e->getCode(), $e); |
49 | 52 | } |