@@ -30,7 +30,7 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | protected function authorize(string $permission, array $context = []): bool |
| 32 | 32 | { |
| 33 | - if (!$this->allows($permission, $context)) { |
|
| 33 | + if (!$this->allows($permission, $context)){ |
|
| 34 | 34 | $name = $this->resolvePermission($permission); |
| 35 | 35 | |
| 36 | 36 | throw new ControllerException( |
@@ -30,7 +30,8 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | protected function authorize(string $permission, array $context = []): bool |
| 32 | 32 | { |
| 33 | - if (!$this->allows($permission, $context)) { |
|
| 33 | + if (!$this->allows($permission, $context)) |
|
| 34 | + { |
|
| 34 | 35 | $name = $this->resolvePermission($permission); |
| 35 | 36 | |
| 36 | 37 | throw new ControllerException( |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | EnvironmentInterface $environment, |
| 41 | 41 | FinalizerInterface $finalizer, |
| 42 | 42 | ContainerInterface $container |
| 43 | - ) { |
|
| 43 | + ){ |
|
| 44 | 44 | $this->environment = $environment; |
| 45 | 45 | $this->finalizer = $finalizer; |
| 46 | 46 | $this->container = $container; |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $worker = new Worker(new StreamRelay(STDIN, STDOUT)); |
| 63 | 63 | |
| 64 | - while ($body = $worker->receive($context)) { |
|
| 65 | - try { |
|
| 64 | + while ($body = $worker->receive($context)){ |
|
| 65 | + try{ |
|
| 66 | 66 | $context = json_decode($context, true); |
| 67 | 67 | |
| 68 | 68 | $job = $this->getJob($context['job']); |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | $job->execute($context['id']); |
| 71 | 71 | |
| 72 | 72 | $worker->send("ok"); |
| 73 | - } catch (\Throwable $e) { |
|
| 73 | + }catch (\Throwable $e){ |
|
| 74 | 74 | $this->handleException($worker, $e); |
| 75 | - } finally { |
|
| 75 | + }finally{ |
|
| 76 | 76 | $this->finalizer->finalize(); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | protected function getJob(string $job): JobInterface |
| 86 | 86 | { |
| 87 | 87 | $names = explode('.', $job); |
| 88 | - $names = array_map(function (string $value) { |
|
| 88 | + $names = array_map(function (string $value){ |
|
| 89 | 89 | return Inflector::classify($value); |
| 90 | 90 | }, $names); |
| 91 | 91 | |
| 92 | - try { |
|
| 92 | + try{ |
|
| 93 | 93 | return $this->container->get(join('\\', $names)); |
| 94 | - } catch (ContainerExceptionInterface $e) { |
|
| 94 | + }catch (ContainerExceptionInterface $e){ |
|
| 95 | 95 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | protected function handleException(Worker $worker, \Throwable $e) |
| 104 | 104 | { |
| 105 | - try { |
|
| 105 | + try{ |
|
| 106 | 106 | $this->container->get(SnapshotterInterface::class)->register($e); |
| 107 | - } catch (\Throwable|ContainerExceptionInterface $se) { |
|
| 107 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
| 108 | 108 | // no need to notify when unable to register an exception |
| 109 | 109 | } |
| 110 | 110 | |
@@ -61,8 +61,10 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $worker = new Worker(new StreamRelay(STDIN, STDOUT)); |
| 63 | 63 | |
| 64 | - while ($body = $worker->receive($context)) { |
|
| 65 | - try { |
|
| 64 | + while ($body = $worker->receive($context)) |
|
| 65 | + { |
|
| 66 | + try |
|
| 67 | + { |
|
| 66 | 68 | $context = json_decode($context, true); |
| 67 | 69 | |
| 68 | 70 | $job = $this->getJob($context['job']); |
@@ -70,9 +72,13 @@ discard block |
||
| 70 | 72 | $job->execute($context['id']); |
| 71 | 73 | |
| 72 | 74 | $worker->send("ok"); |
| 73 | - } catch (\Throwable $e) { |
|
| 75 | + } |
|
| 76 | + catch (\Throwable $e) |
|
| 77 | + { |
|
| 74 | 78 | $this->handleException($worker, $e); |
| 75 | - } finally { |
|
| 79 | + } |
|
| 80 | + finally |
|
| 81 | + { |
|
| 76 | 82 | $this->finalizer->finalize(); |
| 77 | 83 | } |
| 78 | 84 | } |
@@ -85,13 +91,17 @@ discard block |
||
| 85 | 91 | protected function getJob(string $job): JobInterface |
| 86 | 92 | { |
| 87 | 93 | $names = explode('.', $job); |
| 88 | - $names = array_map(function (string $value) { |
|
| 94 | + $names = array_map(function (string $value) |
|
| 95 | + { |
|
| 89 | 96 | return Inflector::classify($value); |
| 90 | 97 | }, $names); |
| 91 | 98 | |
| 92 | - try { |
|
| 99 | + try |
|
| 100 | + { |
|
| 93 | 101 | return $this->container->get(join('\\', $names)); |
| 94 | - } catch (ContainerExceptionInterface $e) { |
|
| 102 | + } |
|
| 103 | + catch (ContainerExceptionInterface $e) |
|
| 104 | + { |
|
| 95 | 105 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
| 96 | 106 | } |
| 97 | 107 | } |
@@ -102,9 +112,12 @@ discard block |
||
| 102 | 112 | */ |
| 103 | 113 | protected function handleException(Worker $worker, \Throwable $e) |
| 104 | 114 | { |
| 105 | - try { |
|
| 115 | + try |
|
| 116 | + { |
|
| 106 | 117 | $this->container->get(SnapshotterInterface::class)->register($e); |
| 107 | - } catch (\Throwable|ContainerExceptionInterface $se) { |
|
| 118 | + } |
|
| 119 | + catch (\Throwable|ContainerExceptionInterface $se) |
|
| 120 | + { |
|
| 108 | 121 | // no need to notify when unable to register an exception |
| 109 | 122 | } |
| 110 | 123 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | EnvironmentInterface $environment, |
| 41 | 41 | FinalizerInterface $finalizer, |
| 42 | 42 | ContainerInterface $container |
| 43 | - ) { |
|
| 43 | + ){ |
|
| 44 | 44 | $this->environment = $environment; |
| 45 | 45 | $this->finalizer = $finalizer; |
| 46 | 46 | $this->container = $container; |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | $http = $this->container->get(HttpCore::class); |
| 64 | 64 | $client = $this->psr7Client(); |
| 65 | 65 | |
| 66 | - while ($request = $client->acceptRequest()) { |
|
| 67 | - try { |
|
| 66 | + while ($request = $client->acceptRequest()){ |
|
| 67 | + try{ |
|
| 68 | 68 | $client->respond($http->handle($request)); |
| 69 | - } catch (\Throwable $e) { |
|
| 69 | + }catch (\Throwable $e){ |
|
| 70 | 70 | $this->handleException($client, $e); |
| 71 | - } finally { |
|
| 71 | + }finally{ |
|
| 72 | 72 | $this->finalizer->finalize(); |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | $handler = new HtmlHandler(HtmlHandler::INVERTED); |
| 94 | 94 | |
| 95 | - try { |
|
| 95 | + try{ |
|
| 96 | 96 | /** @var SnapshotInterface $snapshot */ |
| 97 | 97 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
| 98 | 98 | error_log($snapshot->getMessage()); |
| 99 | - } catch (\Throwable|ContainerExceptionInterface $se) { |
|
| 99 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
| 100 | 100 | error_log($handler->getMessage($e)); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -63,12 +63,18 @@ discard block |
||
| 63 | 63 | $http = $this->container->get(HttpCore::class); |
| 64 | 64 | $client = $this->psr7Client(); |
| 65 | 65 | |
| 66 | - while ($request = $client->acceptRequest()) { |
|
| 67 | - try { |
|
| 66 | + while ($request = $client->acceptRequest()) |
|
| 67 | + { |
|
| 68 | + try |
|
| 69 | + { |
|
| 68 | 70 | $client->respond($http->handle($request)); |
| 69 | - } catch (\Throwable $e) { |
|
| 71 | + } |
|
| 72 | + catch (\Throwable $e) |
|
| 73 | + { |
|
| 70 | 74 | $this->handleException($client, $e); |
| 71 | - } finally { |
|
| 75 | + } |
|
| 76 | + finally |
|
| 77 | + { |
|
| 72 | 78 | $this->finalizer->finalize(); |
| 73 | 79 | } |
| 74 | 80 | } |
@@ -92,11 +98,14 @@ discard block |
||
| 92 | 98 | { |
| 93 | 99 | $handler = new HtmlHandler(HtmlHandler::INVERTED); |
| 94 | 100 | |
| 95 | - try { |
|
| 101 | + try |
|
| 102 | + { |
|
| 96 | 103 | /** @var SnapshotInterface $snapshot */ |
| 97 | 104 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
| 98 | 105 | error_log($snapshot->getMessage()); |
| 99 | - } catch (\Throwable|ContainerExceptionInterface $se) { |
|
| 106 | + } |
|
| 107 | + catch (\Throwable|ContainerExceptionInterface $se) |
|
| 108 | + { |
|
| 100 | 109 | error_log($handler->getMessage($e)); |
| 101 | 110 | } |
| 102 | 111 | |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | KernelInterface $kernel, |
| 38 | 38 | ConsoleDispatcher $console, |
| 39 | 39 | ConfiguratorInterface $configurator |
| 40 | - ) { |
|
| 40 | + ){ |
|
| 41 | 41 | $kernel->addDispatcher($console); |
| 42 | 42 | |
| 43 | 43 | $configurator->setDefaults('console', [ |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | KernelInterface $kernel, |
| 54 | 54 | HttpDispatcher $http, |
| 55 | 55 | ConfiguratorInterface $configurator |
| 56 | - ) { |
|
| 56 | + ){ |
|
| 57 | 57 | $kernel->addDispatcher($http); |
| 58 | 58 | |
| 59 | 59 | $configurator->setDefaults('http', [ |
@@ -44,21 +44,21 @@ |
||
| 44 | 44 | { |
| 45 | 45 | $conn = $environment->get('RR_RPC', static::RPC_DEFAULT); |
| 46 | 46 | |
| 47 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 47 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)){ |
|
| 48 | 48 | throw new RoadRunnerException( |
| 49 | 49 | "Unable to create RPC connection, invalid DSN given `{$conn}`." |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 53 | + if (!in_array($parts[1], ['tcp', 'unix'])){ |
|
| 54 | 54 | throw new RoadRunnerException( |
| 55 | 55 | "Unable to create RPC connection, invalid DSN given `{$conn}`." |
| 56 | 56 | ); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ($parts[1] == 'unix') { |
|
| 59 | + if ($parts[1] == 'unix'){ |
|
| 60 | 60 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 61 | - } else { |
|
| 61 | + }else{ |
|
| 62 | 62 | $relay = new SocketRelay($parts[2], $parts[3], SocketRelay::SOCK_TCP); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -44,21 +44,26 @@ |
||
| 44 | 44 | { |
| 45 | 45 | $conn = $environment->get('RR_RPC', static::RPC_DEFAULT); |
| 46 | 46 | |
| 47 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 47 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) |
|
| 48 | + { |
|
| 48 | 49 | throw new RoadRunnerException( |
| 49 | 50 | "Unable to create RPC connection, invalid DSN given `{$conn}`." |
| 50 | 51 | ); |
| 51 | 52 | } |
| 52 | 53 | |
| 53 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 54 | + if (!in_array($parts[1], ['tcp', 'unix'])) |
|
| 55 | + { |
|
| 54 | 56 | throw new RoadRunnerException( |
| 55 | 57 | "Unable to create RPC connection, invalid DSN given `{$conn}`." |
| 56 | 58 | ); |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | - if ($parts[1] == 'unix') { |
|
| 61 | + if ($parts[1] == 'unix') |
|
| 62 | + { |
|
| 60 | 63 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 61 | - } else { |
|
| 64 | + } |
|
| 65 | + else |
|
| 66 | + { |
|
| 62 | 67 | $relay = new SocketRelay($parts[2], $parts[3], SocketRelay::SOCK_TCP); |
| 63 | 68 | } |
| 64 | 69 | |
@@ -95,7 +95,7 @@ |
||
| 95 | 95 | $configurator->modify('tokenizer', new AppendPatch( |
| 96 | 96 | 'directories', |
| 97 | 97 | null, |
| 98 | - directory('vendor') . 'spiral/validation/src/' |
|
| 98 | + directory('vendor').'spiral/validation/src/' |
|
| 99 | 99 | )); |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | \ No newline at end of file |
@@ -55,23 +55,23 @@ |
||
| 55 | 55 | '<fg=magenta>[console]</fg=magenta> <fg=cyan>re-index available console commands...</fg=cyan>' |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - if ($container->has(TranslatorInterface::class)) { |
|
| 58 | + if ($container->has(TranslatorInterface::class)){ |
|
| 59 | 59 | $this->configureTranslator($console); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ($container->has(MapperInterface::class)) { |
|
| 62 | + if ($container->has(MapperInterface::class)){ |
|
| 63 | 63 | $this->configureFilters($console); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ($container->has(DatabaseInterface::class)) { |
|
| 66 | + if ($container->has(DatabaseInterface::class)){ |
|
| 67 | 67 | $this->configureDatabase($console); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ($container->has(ViewsInterface::class)) { |
|
| 70 | + if ($container->has(ViewsInterface::class)){ |
|
| 71 | 71 | $this->configureViews($console); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ($container->has(Migrator::class)) { |
|
| 74 | + if ($container->has(Migrator::class)){ |
|
| 75 | 75 | $this->configureMigrations($console); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -55,23 +55,28 @@ |
||
| 55 | 55 | '<fg=magenta>[console]</fg=magenta> <fg=cyan>re-index available console commands...</fg=cyan>' |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - if ($container->has(TranslatorInterface::class)) { |
|
| 58 | + if ($container->has(TranslatorInterface::class)) |
|
| 59 | + { |
|
| 59 | 60 | $this->configureTranslator($console); |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | - if ($container->has(MapperInterface::class)) { |
|
| 63 | + if ($container->has(MapperInterface::class)) |
|
| 64 | + { |
|
| 63 | 65 | $this->configureFilters($console); |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | - if ($container->has(DatabaseInterface::class)) { |
|
| 68 | + if ($container->has(DatabaseInterface::class)) |
|
| 69 | + { |
|
| 67 | 70 | $this->configureDatabase($console); |
| 68 | 71 | } |
| 69 | 72 | |
| 70 | - if ($container->has(ViewsInterface::class)) { |
|
| 73 | + if ($container->has(ViewsInterface::class)) |
|
| 74 | + { |
|
| 71 | 75 | $this->configureViews($console); |
| 72 | 76 | } |
| 73 | 77 | |
| 74 | - if ($container->has(Migrator::class)) { |
|
| 78 | + if ($container->has(Migrator::class)) |
|
| 79 | + { |
|
| 75 | 80 | $this->configureMigrations($console); |
| 76 | 81 | } |
| 77 | 82 | } |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | 'cookie' => 'session', |
| 46 | 46 | 'secure' => false, |
| 47 | 47 | 'handler' => new Autowire(FileHandler::class, [ |
| 48 | - 'directory' => $directories->get('runtime') . 'session', |
|
| 48 | + 'directory' => $directories->get('runtime').'session', |
|
| 49 | 49 | 'lifetime' => 86400 |
| 50 | 50 | ] |
| 51 | 51 | ) |