@@ -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; |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | /** @var Http $http */ |
| 82 | 82 | $http = $this->container->get(Http::class); |
| 83 | 83 | |
| 84 | - while ($request = $this->worker->waitRequest()) { |
|
| 85 | - try { |
|
| 84 | + while ($request = $this->worker->waitRequest()){ |
|
| 85 | + try{ |
|
| 86 | 86 | $response = $http->handle($request); |
| 87 | 87 | |
| 88 | 88 | $this->worker->respond($response); |
| 89 | - } catch (\Throwable $e) { |
|
| 89 | + }catch (\Throwable $e){ |
|
| 90 | 90 | $this->worker->respond($this->errorToResponse($e)); |
| 91 | - } finally { |
|
| 91 | + }finally{ |
|
| 92 | 92 | $this->finalizer->finalize(false); |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | $handler = new HtmlHandler(); |
| 104 | 104 | |
| 105 | - try { |
|
| 105 | + try{ |
|
| 106 | 106 | /** @var SnapshotInterface $snapshot */ |
| 107 | 107 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
| 108 | 108 | \file_put_contents('php://stderr', $snapshot->getMessage()); |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | // on demand |
| 111 | 111 | $state = $this->container->get(StateInterface::class); |
| 112 | 112 | |
| 113 | - if ($state !== null) { |
|
| 113 | + if ($state !== null){ |
|
| 114 | 114 | $handler = $handler->withState($state); |
| 115 | 115 | } |
| 116 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 116 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
| 117 | 117 | \file_put_contents('php://stderr', (string)$e); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -81,14 +81,20 @@ discard block |
||
| 81 | 81 | /** @var Http $http */ |
| 82 | 82 | $http = $this->container->get(Http::class); |
| 83 | 83 | |
| 84 | - while ($request = $this->worker->waitRequest()) { |
|
| 85 | - try { |
|
| 84 | + while ($request = $this->worker->waitRequest()) |
|
| 85 | + { |
|
| 86 | + try |
|
| 87 | + { |
|
| 86 | 88 | $response = $http->handle($request); |
| 87 | 89 | |
| 88 | 90 | $this->worker->respond($response); |
| 89 | - } catch (\Throwable $e) { |
|
| 91 | + } |
|
| 92 | + catch (\Throwable $e) |
|
| 93 | + { |
|
| 90 | 94 | $this->worker->respond($this->errorToResponse($e)); |
| 91 | - } finally { |
|
| 95 | + } |
|
| 96 | + finally |
|
| 97 | + { |
|
| 92 | 98 | $this->finalizer->finalize(false); |
| 93 | 99 | } |
| 94 | 100 | } |
@@ -102,7 +108,8 @@ discard block |
||
| 102 | 108 | { |
| 103 | 109 | $handler = new HtmlHandler(); |
| 104 | 110 | |
| 105 | - try { |
|
| 111 | + try |
|
| 112 | + { |
|
| 106 | 113 | /** @var SnapshotInterface $snapshot */ |
| 107 | 114 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
| 108 | 115 | \file_put_contents('php://stderr', $snapshot->getMessage()); |
@@ -110,10 +117,13 @@ discard block |
||
| 110 | 117 | // on demand |
| 111 | 118 | $state = $this->container->get(StateInterface::class); |
| 112 | 119 | |
| 113 | - if ($state !== null) { |
|
| 120 | + if ($state !== null) |
|
| 121 | + { |
|
| 114 | 122 | $handler = $handler->withState($state); |
| 115 | 123 | } |
| 116 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 124 | + } |
|
| 125 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
| 126 | + { |
|
| 117 | 127 | \file_put_contents('php://stderr', (string)$e); |
| 118 | 128 | } |
| 119 | 129 | |
@@ -43,8 +43,8 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $state->setTag('php', phpversion()); |
| 45 | 45 | |
| 46 | - if ($this->container->has(DispatcherInterface::class)) { |
|
| 47 | - switch (get_class($this->container->get(DispatcherInterface::class))) { |
|
| 46 | + if ($this->container->has(DispatcherInterface::class)){ |
|
| 47 | + switch (get_class($this->container->get(DispatcherInterface::class))){ |
|
| 48 | 48 | case LegacyRrDispatcher::class: |
| 49 | 49 | $state->setTag('dispatcher', 'roadrunner'); |
| 50 | 50 | break; |
@@ -43,8 +43,10 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $state->setTag('php', phpversion()); |
| 45 | 45 | |
| 46 | - if ($this->container->has(DispatcherInterface::class)) { |
|
| 47 | - switch (get_class($this->container->get(DispatcherInterface::class))) { |
|
| 46 | + if ($this->container->has(DispatcherInterface::class)) |
|
| 47 | + { |
|
| 48 | + switch (get_class($this->container->get(DispatcherInterface::class))) |
|
| 49 | + { |
|
| 48 | 50 | case LegacyRrDispatcher::class: |
| 49 | 51 | $state->setTag('dispatcher', 'roadrunner'); |
| 50 | 52 | break; |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function boot(Container $container) |
| 41 | 41 | { |
| 42 | - $container->bindSingleton(RPC::class, function (EnvironmentInterface $env) { |
|
| 42 | + $container->bindSingleton(RPC::class, function (EnvironmentInterface $env){ |
|
| 43 | 43 | return $this->rpc($env); |
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | - $container->bindSingleton(Worker::class, function (EnvironmentInterface $env) { |
|
| 46 | + $container->bindSingleton(Worker::class, function (EnvironmentInterface $env){ |
|
| 47 | 47 | return $this->worker($env); |
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | - $container->bindSingleton(MetricsInterface::class, function (RPC $rpc) { |
|
| 50 | + $container->bindSingleton(MetricsInterface::class, function (RPC $rpc){ |
|
| 51 | 51 | return new Metrics($rpc); |
| 52 | 52 | }); |
| 53 | 53 | } |
@@ -60,21 +60,21 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | $conn = $env->get('RR_RPC', self::RPC_DEFAULT); |
| 62 | 62 | |
| 63 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 63 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)){ |
|
| 64 | 64 | throw new BootException( |
| 65 | 65 | "Unable to configure RPC connection, invalid DSN given `{$conn}`." |
| 66 | 66 | ); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 69 | + if (!in_array($parts[1], ['tcp', 'unix'])){ |
|
| 70 | 70 | throw new BootException( |
| 71 | 71 | "Unable to configure RPC connection, invalid DSN given `{$conn}`." |
| 72 | 72 | ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ($parts[1] == 'unix') { |
|
| 75 | + if ($parts[1] == 'unix'){ |
|
| 76 | 76 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 77 | - } else { |
|
| 77 | + }else{ |
|
| 78 | 78 | $relay = new SocketRelay($parts[2], (int)$parts[3], SocketRelay::SOCK_TCP); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -89,25 +89,25 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | $conn = $env->get('RR_RELAY', self::WORKER_DEFAULT); |
| 91 | 91 | |
| 92 | - if ($conn === 'pipes' || empty($conn)) { |
|
| 92 | + if ($conn === 'pipes' || empty($conn)){ |
|
| 93 | 93 | return new Worker(new StreamRelay(STDIN, STDOUT)); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 96 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)){ |
|
| 97 | 97 | throw new BootException( |
| 98 | 98 | "Unable to configure Worker connection, invalid DSN given `{$conn}`." |
| 99 | 99 | ); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 102 | + if (!in_array($parts[1], ['tcp', 'unix'])){ |
|
| 103 | 103 | throw new BootException( |
| 104 | 104 | "Unable to configure Worker connection, invalid DSN given `{$conn}`." |
| 105 | 105 | ); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ($parts[1] == 'unix') { |
|
| 108 | + if ($parts[1] == 'unix'){ |
|
| 109 | 109 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 110 | - } else { |
|
| 110 | + }else{ |
|
| 111 | 111 | $relay = new SocketRelay($parts[2], (int)$parts[3], SocketRelay::SOCK_TCP); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -39,15 +39,18 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function boot(Container $container) |
| 41 | 41 | { |
| 42 | - $container->bindSingleton(RPC::class, function (EnvironmentInterface $env) { |
|
| 42 | + $container->bindSingleton(RPC::class, function (EnvironmentInterface $env) |
|
| 43 | + { |
|
| 43 | 44 | return $this->rpc($env); |
| 44 | 45 | }); |
| 45 | 46 | |
| 46 | - $container->bindSingleton(Worker::class, function (EnvironmentInterface $env) { |
|
| 47 | + $container->bindSingleton(Worker::class, function (EnvironmentInterface $env) |
|
| 48 | + { |
|
| 47 | 49 | return $this->worker($env); |
| 48 | 50 | }); |
| 49 | 51 | |
| 50 | - $container->bindSingleton(MetricsInterface::class, function (RPC $rpc) { |
|
| 52 | + $container->bindSingleton(MetricsInterface::class, function (RPC $rpc) |
|
| 53 | + { |
|
| 51 | 54 | return new Metrics($rpc); |
| 52 | 55 | }); |
| 53 | 56 | } |
@@ -60,21 +63,26 @@ discard block |
||
| 60 | 63 | { |
| 61 | 64 | $conn = $env->get('RR_RPC', self::RPC_DEFAULT); |
| 62 | 65 | |
| 63 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 66 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) |
|
| 67 | + { |
|
| 64 | 68 | throw new BootException( |
| 65 | 69 | "Unable to configure RPC connection, invalid DSN given `{$conn}`." |
| 66 | 70 | ); |
| 67 | 71 | } |
| 68 | 72 | |
| 69 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 73 | + if (!in_array($parts[1], ['tcp', 'unix'])) |
|
| 74 | + { |
|
| 70 | 75 | throw new BootException( |
| 71 | 76 | "Unable to configure RPC connection, invalid DSN given `{$conn}`." |
| 72 | 77 | ); |
| 73 | 78 | } |
| 74 | 79 | |
| 75 | - if ($parts[1] == 'unix') { |
|
| 80 | + if ($parts[1] == 'unix') |
|
| 81 | + { |
|
| 76 | 82 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 77 | - } else { |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 78 | 86 | $relay = new SocketRelay($parts[2], (int)$parts[3], SocketRelay::SOCK_TCP); |
| 79 | 87 | } |
| 80 | 88 | |
@@ -89,25 +97,31 @@ discard block |
||
| 89 | 97 | { |
| 90 | 98 | $conn = $env->get('RR_RELAY', self::WORKER_DEFAULT); |
| 91 | 99 | |
| 92 | - if ($conn === 'pipes' || empty($conn)) { |
|
| 100 | + if ($conn === 'pipes' || empty($conn)) |
|
| 101 | + { |
|
| 93 | 102 | return new Worker(new StreamRelay(STDIN, STDOUT)); |
| 94 | 103 | } |
| 95 | 104 | |
| 96 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 105 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) |
|
| 106 | + { |
|
| 97 | 107 | throw new BootException( |
| 98 | 108 | "Unable to configure Worker connection, invalid DSN given `{$conn}`." |
| 99 | 109 | ); |
| 100 | 110 | } |
| 101 | 111 | |
| 102 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 112 | + if (!in_array($parts[1], ['tcp', 'unix'])) |
|
| 113 | + { |
|
| 103 | 114 | throw new BootException( |
| 104 | 115 | "Unable to configure Worker connection, invalid DSN given `{$conn}`." |
| 105 | 116 | ); |
| 106 | 117 | } |
| 107 | 118 | |
| 108 | - if ($parts[1] == 'unix') { |
|
| 119 | + if ($parts[1] == 'unix') |
|
| 120 | + { |
|
| 109 | 121 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 110 | - } else { |
|
| 122 | + } |
|
| 123 | + else |
|
| 124 | + { |
|
| 111 | 125 | $relay = new SocketRelay($parts[2], (int)$parts[3], SocketRelay::SOCK_TCP); |
| 112 | 126 | } |
| 113 | 127 | |
@@ -76,11 +76,11 @@ |
||
| 76 | 76 | |
| 77 | 77 | $kernel->addDispatcher($factory->make(SapiDispatcher::class)); |
| 78 | 78 | |
| 79 | - if (class_exists(PSR7Client::class)) { |
|
| 79 | + if (class_exists(PSR7Client::class)){ |
|
| 80 | 80 | $kernel->addDispatcher($factory->make(LegacyRrDispatcher::class)); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if (class_exists(PSR7Worker::class)) { |
|
| 83 | + if (class_exists(PSR7Worker::class)){ |
|
| 84 | 84 | $kernel->addDispatcher($factory->make(RrDispatcher::class)); |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -76,11 +76,13 @@ |
||
| 76 | 76 | |
| 77 | 77 | $kernel->addDispatcher($factory->make(SapiDispatcher::class)); |
| 78 | 78 | |
| 79 | - if (class_exists(PSR7Client::class)) { |
|
| 79 | + if (class_exists(PSR7Client::class)) |
|
| 80 | + { |
|
| 80 | 81 | $kernel->addDispatcher($factory->make(LegacyRrDispatcher::class)); |
| 81 | 82 | } |
| 82 | 83 | |
| 83 | - if (class_exists(PSR7Worker::class)) { |
|
| 84 | + if (class_exists(PSR7Worker::class)) |
|
| 85 | + { |
|
| 84 | 86 | $kernel->addDispatcher($factory->make(RrDispatcher::class)); |
| 85 | 87 | } |
| 86 | 88 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | private function isLegacy(): bool |
| 44 | 44 | { |
| 45 | - if (\class_exists(InstalledVersions::class)) { |
|
| 45 | + if (\class_exists(InstalledVersions::class)){ |
|
| 46 | 46 | $version = InstalledVersions::getVersion('spiral/roadrunner'); |
| 47 | 47 | |
| 48 | 48 | return \str_starts_with($version, '1.'); |
@@ -42,7 +42,8 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | private function isLegacy(): bool |
| 44 | 44 | { |
| 45 | - if (\class_exists(InstalledVersions::class)) { |
|
| 45 | + if (\class_exists(InstalledVersions::class)) |
|
| 46 | + { |
|
| 46 | 47 | $version = InstalledVersions::getVersion('spiral/roadrunner'); |
| 47 | 48 | |
| 48 | 49 | return \str_starts_with($version, '1.'); |
@@ -47,12 +47,12 @@ |
||
| 47 | 47 | { |
| 48 | 48 | $kernel->addDispatcher($jobs); |
| 49 | 49 | |
| 50 | - if (\class_exists(LegacyRPC::class)) { |
|
| 51 | - $container->bindSingleton(QueueInterface::class, function (LegacyRPC $rpc, JobRegistry $registry) { |
|
| 50 | + if (\class_exists(LegacyRPC::class)){ |
|
| 51 | + $container->bindSingleton(QueueInterface::class, function (LegacyRPC $rpc, JobRegistry $registry){ |
|
| 52 | 52 | return new JobQueue($rpc, $registry); |
| 53 | 53 | }); |
| 54 | - } else { |
|
| 55 | - $container->bindSingleton(QueueInterface::class, function (RPC $rpc, JobRegistry $registry) { |
|
| 54 | + }else{ |
|
| 55 | + $container->bindSingleton(QueueInterface::class, function (RPC $rpc, JobRegistry $registry){ |
|
| 56 | 56 | return new JobQueue($rpc, $registry); |
| 57 | 57 | }); |
| 58 | 58 | } |
@@ -47,12 +47,17 @@ |
||
| 47 | 47 | { |
| 48 | 48 | $kernel->addDispatcher($jobs); |
| 49 | 49 | |
| 50 | - if (\class_exists(LegacyRPC::class)) { |
|
| 51 | - $container->bindSingleton(QueueInterface::class, function (LegacyRPC $rpc, JobRegistry $registry) { |
|
| 50 | + if (\class_exists(LegacyRPC::class)) |
|
| 51 | + { |
|
| 52 | + $container->bindSingleton(QueueInterface::class, function (LegacyRPC $rpc, JobRegistry $registry) |
|
| 53 | + { |
|
| 52 | 54 | return new JobQueue($rpc, $registry); |
| 53 | 55 | }); |
| 54 | - } else { |
|
| 55 | - $container->bindSingleton(QueueInterface::class, function (RPC $rpc, JobRegistry $registry) { |
|
| 56 | + } |
|
| 57 | + else |
|
| 58 | + { |
|
| 59 | + $container->bindSingleton(QueueInterface::class, function (RPC $rpc, JobRegistry $registry) |
|
| 60 | + { |
|
| 56 | 61 | return new JobQueue($rpc, $registry); |
| 57 | 62 | }); |
| 58 | 63 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | 45 | $psr->shouldReceive('respond')->once()->with( |
| 46 | - \Mockery::on(function ($r) { |
|
| 46 | + \Mockery::on(function ($r){ |
|
| 47 | 47 | $this->assertSame('Hello, dave.', (string)$r->getBody()); |
| 48 | 48 | return true; |
| 49 | 49 | }) |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | 67 | $psr->shouldReceive('respond')->once()->with( |
| 68 | - \Mockery::on(function ($r) { |
|
| 68 | + \Mockery::on(function ($r){ |
|
| 69 | 69 | $this->assertStringContainsString('500', (string)$r->getBody()); |
| 70 | 70 | return true; |
| 71 | 71 | }) |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $psr->shouldReceive('acceptRequest')->once()->andReturn(null); |
| 75 | 75 | |
| 76 | 76 | $files = $this->app->get(FilesInterface::class)->getFiles( |
| 77 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
| 77 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | 80 | $this->assertCount(0, $files); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $this->app->get(LegacyRrDispatcher::class)->serve($psr); |
| 83 | 83 | |
| 84 | 84 | $files = $this->app->get(FilesInterface::class)->getFiles( |
| 85 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
| 85 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | 88 | $this->assertCount(1, $files); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | ); |
| 104 | 104 | |
| 105 | 105 | $psr->shouldReceive('respond')->once()->with( |
| 106 | - \Mockery::on(function ($r) { |
|
| 106 | + \Mockery::on(function ($r){ |
|
| 107 | 107 | $this->assertStringContainsString('undefined', (string)$r->getBody()); |
| 108 | 108 | return true; |
| 109 | 109 | }) |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $psr->shouldReceive('acceptRequest')->once()->andReturn(null); |
| 113 | 113 | |
| 114 | 114 | $files = $this->app->get(FilesInterface::class)->getFiles( |
| 115 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
| 115 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | 118 | $this->assertCount(0, $files); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $this->app->get(LegacyRrDispatcher::class)->serve($psr); |
| 121 | 121 | |
| 122 | 122 | $files = $this->app->get(FilesInterface::class)->getFiles( |
| 123 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
| 123 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | 126 | $this->assertCount(1, $files); |