@@ -54,7 +54,8 @@ |
||
| 54 | 54 | return $source->withCode( |
| 55 | 55 | preg_replace_callback( |
| 56 | 56 | self::REGEXP, |
| 57 | - function ($matches) use ($domain, $context) { |
|
| 57 | + function ($matches) use ($domain, $context) |
|
| 58 | + { |
|
| 58 | 59 | return $this->translator->trans( |
| 59 | 60 | $matches[1], |
| 60 | 61 | [], |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | RendererInterface $renderer, |
| 58 | 58 | ResponseFactoryInterface $responseFactory, |
| 59 | 59 | ContainerInterface $container |
| 60 | - ) { |
|
| 60 | + ){ |
|
| 61 | 61 | $this->suppressErrors = $suppressErrors; |
| 62 | 62 | $this->renderer = $renderer; |
| 63 | 63 | $this->responseFactory = $responseFactory; |
@@ -71,22 +71,22 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function process(Request $request, Handler $handler): Response |
| 73 | 73 | { |
| 74 | - try { |
|
| 74 | + try{ |
|
| 75 | 75 | return $handler->handle($request); |
| 76 | - } catch (ClientException | RouterException $e) { |
|
| 77 | - if ($e instanceof ClientException) { |
|
| 76 | + }catch (ClientException | RouterException $e){ |
|
| 77 | + if ($e instanceof ClientException){ |
|
| 78 | 78 | $code = $e->getCode(); |
| 79 | - } else { |
|
| 79 | + }else{ |
|
| 80 | 80 | $code = 404; |
| 81 | 81 | } |
| 82 | - } catch (\Throwable $e) { |
|
| 82 | + }catch (\Throwable $e){ |
|
| 83 | 83 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
| 84 | - if ($snapshotter !== null) { |
|
| 84 | + if ($snapshotter !== null){ |
|
| 85 | 85 | /** @var SnapshotterInterface $snapshotter */ |
| 86 | 86 | $snapshotter->register($e); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if (!$this->suppressErrors) { |
|
| 89 | + if (!$this->suppressErrors){ |
|
| 90 | 90 | return $this->renderError($request, $e); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | $response = $this->responseFactory->createResponse(500); |
| 111 | 111 | |
| 112 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
| 112 | + if ($request->getHeaderLine('Accept') == 'application/json'){ |
|
| 113 | 113 | $response = $response->withHeader('Content-Type', 'application/json'); |
| 114 | 114 | $handler = new JsonHandler(); |
| 115 | 115 | $response->getBody()->write( |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | ) |
| 122 | 122 | ) |
| 123 | 123 | ); |
| 124 | - } else { |
|
| 124 | + }else{ |
|
| 125 | 125 | $handler = new HtmlHandler(); |
| 126 | 126 | $state = $this->getOptional(StateInterface::class); |
| 127 | - if ($state !== null) { |
|
| 127 | + if ($state !== null){ |
|
| 128 | 128 | $handler = $handler->withState($state); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | private function getOptional(string $class) |
| 162 | 162 | { |
| 163 | - try { |
|
| 163 | + try{ |
|
| 164 | 164 | return $this->container->get($class); |
| 165 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 165 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
| 166 | 166 | return null; |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -71,22 +71,32 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function process(Request $request, Handler $handler): Response |
| 73 | 73 | { |
| 74 | - try { |
|
| 74 | + try |
|
| 75 | + { |
|
| 75 | 76 | return $handler->handle($request); |
| 76 | - } catch (ClientException | RouterException $e) { |
|
| 77 | - if ($e instanceof ClientException) { |
|
| 77 | + } |
|
| 78 | + catch (ClientException | RouterException $e) |
|
| 79 | + { |
|
| 80 | + if ($e instanceof ClientException) |
|
| 81 | + { |
|
| 78 | 82 | $code = $e->getCode(); |
| 79 | - } else { |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 80 | 86 | $code = 404; |
| 81 | 87 | } |
| 82 | - } catch (\Throwable $e) { |
|
| 88 | + } |
|
| 89 | + catch (\Throwable $e) |
|
| 90 | + { |
|
| 83 | 91 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
| 84 | - if ($snapshotter !== null) { |
|
| 92 | + if ($snapshotter !== null) |
|
| 93 | + { |
|
| 85 | 94 | /** @var SnapshotterInterface $snapshotter */ |
| 86 | 95 | $snapshotter->register($e); |
| 87 | 96 | } |
| 88 | 97 | |
| 89 | - if (!$this->suppressErrors) { |
|
| 98 | + if (!$this->suppressErrors) |
|
| 99 | + { |
|
| 90 | 100 | return $this->renderError($request, $e); |
| 91 | 101 | } |
| 92 | 102 | |
@@ -109,7 +119,8 @@ discard block |
||
| 109 | 119 | { |
| 110 | 120 | $response = $this->responseFactory->createResponse(500); |
| 111 | 121 | |
| 112 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
| 122 | + if ($request->getHeaderLine('Accept') == 'application/json') |
|
| 123 | + { |
|
| 113 | 124 | $response = $response->withHeader('Content-Type', 'application/json'); |
| 114 | 125 | $handler = new JsonHandler(); |
| 115 | 126 | $response->getBody()->write( |
@@ -121,10 +132,13 @@ discard block |
||
| 121 | 132 | ) |
| 122 | 133 | ) |
| 123 | 134 | ); |
| 124 | - } else { |
|
| 135 | + } |
|
| 136 | + else |
|
| 137 | + { |
|
| 125 | 138 | $handler = new HtmlHandler(); |
| 126 | 139 | $state = $this->getOptional(StateInterface::class); |
| 127 | - if ($state !== null) { |
|
| 140 | + if ($state !== null) |
|
| 141 | + { |
|
| 128 | 142 | $handler = $handler->withState($state); |
| 129 | 143 | } |
| 130 | 144 | |
@@ -160,9 +174,12 @@ discard block |
||
| 160 | 174 | */ |
| 161 | 175 | private function getOptional(string $class) |
| 162 | 176 | { |
| 163 | - try { |
|
| 177 | + try |
|
| 178 | + { |
|
| 164 | 179 | return $this->container->get($class); |
| 165 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 180 | + } |
|
| 181 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
| 182 | + { |
|
| 166 | 183 | return null; |
| 167 | 184 | } |
| 168 | 185 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | EnvironmentInterface $env, |
| 40 | 40 | FinalizerInterface $finalizer, |
| 41 | 41 | ContainerInterface $container |
| 42 | - ) { |
|
| 42 | + ){ |
|
| 43 | 43 | $this->env = $env; |
| 44 | 44 | $this->finalizer = $finalizer; |
| 45 | 45 | $this->container = $container; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $consumer->serve( |
| 71 | 71 | $worker, |
| 72 | 72 | function (\Throwable $e = null): void { |
| 73 | - if ($e !== null) { |
|
| 73 | + if ($e !== null){ |
|
| 74 | 74 | $this->handleException($e); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | protected function handleException(\Throwable $e): void |
| 86 | 86 | { |
| 87 | - try { |
|
| 87 | + try{ |
|
| 88 | 88 | $this->container->get(SnapshotterInterface::class)->register($e); |
| 89 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 89 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
| 90 | 90 | // no need to notify when unable to register an exception |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -70,7 +70,8 @@ discard block |
||
| 70 | 70 | $consumer->serve( |
| 71 | 71 | $worker, |
| 72 | 72 | function (\Throwable $e = null): void { |
| 73 | - if ($e !== null) { |
|
| 73 | + if ($e !== null) |
|
| 74 | + { |
|
| 74 | 75 | $this->handleException($e); |
| 75 | 76 | } |
| 76 | 77 | |
@@ -84,9 +85,12 @@ discard block |
||
| 84 | 85 | */ |
| 85 | 86 | protected function handleException(\Throwable $e): void |
| 86 | 87 | { |
| 87 | - try { |
|
| 88 | + try |
|
| 89 | + { |
|
| 88 | 90 | $this->container->get(SnapshotterInterface::class)->register($e); |
| 89 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 91 | + } |
|
| 92 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
| 93 | + { |
|
| 90 | 94 | // no need to notify when unable to register an exception |
| 91 | 95 | } |
| 92 | 96 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | $runtimeDirectory = $this->dirs->get('runtime'); |
| 47 | 47 | |
| 48 | - if (!$this->files->exists($runtimeDirectory)) { |
|
| 48 | + if (!$this->files->exists($runtimeDirectory)){ |
|
| 49 | 49 | $this->files->ensureDirectory($runtimeDirectory); |
| 50 | 50 | $output->writeln('<comment>created</comment>'); |
| 51 | 51 | return; |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | $output->writeln('<info>exists</info>'); |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - foreach ($this->files->getFiles($runtimeDirectory) as $filename) { |
|
| 57 | - try { |
|
| 56 | + foreach ($this->files->getFiles($runtimeDirectory) as $filename){ |
|
| 57 | + try{ |
|
| 58 | 58 | $this->files->setPermissions($filename, FilesInterface::RUNTIME); |
| 59 | 59 | $this->files->setPermissions(dirname($filename), FilesInterface::RUNTIME); |
| 60 | - } catch (\Throwable $e) { |
|
| 60 | + }catch (\Throwable $e){ |
|
| 61 | 61 | // @codeCoverageIgnoreStart |
| 62 | 62 | $output->writeln( |
| 63 | 63 | sprintf( |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | // @codeCoverageIgnoreEnd |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ($output->isVerbose()) { |
|
| 73 | + if ($output->isVerbose()){ |
|
| 74 | 74 | $output->writeln( |
| 75 | 75 | sprintf( |
| 76 | 76 | '<fg=green>[updated]</fg=green> `%s`', |
@@ -45,7 +45,8 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | $runtimeDirectory = $this->dirs->get('runtime'); |
| 47 | 47 | |
| 48 | - if (!$this->files->exists($runtimeDirectory)) { |
|
| 48 | + if (!$this->files->exists($runtimeDirectory)) |
|
| 49 | + { |
|
| 49 | 50 | $this->files->ensureDirectory($runtimeDirectory); |
| 50 | 51 | $output->writeln('<comment>created</comment>'); |
| 51 | 52 | return; |
@@ -53,11 +54,15 @@ discard block |
||
| 53 | 54 | $output->writeln('<info>exists</info>'); |
| 54 | 55 | |
| 55 | 56 | |
| 56 | - foreach ($this->files->getFiles($runtimeDirectory) as $filename) { |
|
| 57 | - try { |
|
| 57 | + foreach ($this->files->getFiles($runtimeDirectory) as $filename) |
|
| 58 | + { |
|
| 59 | + try |
|
| 60 | + { |
|
| 58 | 61 | $this->files->setPermissions($filename, FilesInterface::RUNTIME); |
| 59 | 62 | $this->files->setPermissions(dirname($filename), FilesInterface::RUNTIME); |
| 60 | - } catch (\Throwable $e) { |
|
| 63 | + } |
|
| 64 | + catch (\Throwable $e) |
|
| 65 | + { |
|
| 61 | 66 | // @codeCoverageIgnoreStart |
| 62 | 67 | $output->writeln( |
| 63 | 68 | sprintf( |
@@ -70,7 +75,8 @@ discard block |
||
| 70 | 75 | // @codeCoverageIgnoreEnd |
| 71 | 76 | } |
| 72 | 77 | |
| 73 | - if ($output->isVerbose()) { |
|
| 78 | + if ($output->isVerbose()) |
|
| 79 | + { |
|
| 74 | 80 | $output->writeln( |
| 75 | 81 | sprintf( |
| 76 | 82 | '<fg=green>[updated]</fg=green> `%s`', |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | HandlerInterface $handler, |
| 54 | 54 | FilesInterface $files, |
| 55 | 55 | LoggerInterface $logger = null |
| 56 | - ) { |
|
| 56 | + ){ |
|
| 57 | 57 | $this->directory = $directory; |
| 58 | 58 | $this->maxFiles = $maxFiles; |
| 59 | 59 | $this->verbosity = $verbosity; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $snapshot = new Snapshot($this->getID($e), $e); |
| 71 | 71 | |
| 72 | - if ($this->logger !== null) { |
|
| 72 | + if ($this->logger !== null){ |
|
| 73 | 73 | $this->logger->error($snapshot->getMessage()); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -102,18 +102,18 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | $finder = new Finder(); |
| 104 | 104 | $finder->in($this->directory)->sort( |
| 105 | - function (SplFileInfo $a, SplFileInfo $b) { |
|
| 105 | + function (SplFileInfo $a, SplFileInfo $b){ |
|
| 106 | 106 | return $b->getMTime() - $a->getMTime(); |
| 107 | 107 | } |
| 108 | 108 | ); |
| 109 | 109 | |
| 110 | 110 | $count = 0; |
| 111 | - foreach ($finder as $file) { |
|
| 111 | + foreach ($finder as $file){ |
|
| 112 | 112 | $count++; |
| 113 | - if ($count > $this->maxFiles) { |
|
| 114 | - try { |
|
| 113 | + if ($count > $this->maxFiles){ |
|
| 114 | + try{ |
|
| 115 | 115 | $this->files->delete($file->getRealPath()); |
| 116 | - } catch (FilesException $e) { |
|
| 116 | + }catch (FilesException $e){ |
|
| 117 | 117 | // ignore |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -69,7 +69,8 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $snapshot = new Snapshot($this->getID($e), $e); |
| 71 | 71 | |
| 72 | - if ($this->logger !== null) { |
|
| 72 | + if ($this->logger !== null) |
|
| 73 | + { |
|
| 73 | 74 | $this->logger->error($snapshot->getMessage()); |
| 74 | 75 | } |
| 75 | 76 | |
@@ -102,18 +103,24 @@ discard block |
||
| 102 | 103 | { |
| 103 | 104 | $finder = new Finder(); |
| 104 | 105 | $finder->in($this->directory)->sort( |
| 105 | - function (SplFileInfo $a, SplFileInfo $b) { |
|
| 106 | + function (SplFileInfo $a, SplFileInfo $b) |
|
| 107 | + { |
|
| 106 | 108 | return $b->getMTime() - $a->getMTime(); |
| 107 | 109 | } |
| 108 | 110 | ); |
| 109 | 111 | |
| 110 | 112 | $count = 0; |
| 111 | - foreach ($finder as $file) { |
|
| 113 | + foreach ($finder as $file) |
|
| 114 | + { |
|
| 112 | 115 | $count++; |
| 113 | - if ($count > $this->maxFiles) { |
|
| 114 | - try { |
|
| 116 | + if ($count > $this->maxFiles) |
|
| 117 | + { |
|
| 118 | + try |
|
| 119 | + { |
|
| 115 | 120 | $this->files->delete($file->getRealPath()); |
| 116 | - } catch (FilesException $e) { |
|
| 121 | + } |
|
| 122 | + catch (FilesException $e) |
|
| 123 | + { |
|
| 117 | 124 | // ignore |
| 118 | 125 | } |
| 119 | 126 | } |
@@ -43,29 +43,29 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | protected function mapDirectories(array $directories): array |
| 45 | 45 | { |
| 46 | - if (!isset($directories['root'])) { |
|
| 46 | + if (!isset($directories['root'])){ |
|
| 47 | 47 | throw new BootException('Missing required directory `root`.'); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if (!isset($directories['app'])) { |
|
| 51 | - $directories['app'] = $directories['root'] . '/app/'; |
|
| 50 | + if (!isset($directories['app'])){ |
|
| 51 | + $directories['app'] = $directories['root'].'/app/'; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | return array_merge( |
| 55 | 55 | [ |
| 56 | 56 | // public root |
| 57 | - 'public' => $directories['root'] . '/public/', |
|
| 57 | + 'public' => $directories['root'].'/public/', |
|
| 58 | 58 | |
| 59 | 59 | // vendor libraries |
| 60 | - 'vendor' => $directories['root'] . '/vendor/', |
|
| 60 | + 'vendor' => $directories['root'].'/vendor/', |
|
| 61 | 61 | |
| 62 | 62 | // data directories |
| 63 | - 'runtime' => $directories['root'] . '/runtime/', |
|
| 64 | - 'cache' => $directories['root'] . '/runtime/cache/', |
|
| 63 | + 'runtime' => $directories['root'].'/runtime/', |
|
| 64 | + 'cache' => $directories['root'].'/runtime/cache/', |
|
| 65 | 65 | |
| 66 | 66 | // application directories |
| 67 | - 'config' => $directories['app'] . '/config/', |
|
| 68 | - 'resources' => $directories['app'] . '/resources/', |
|
| 67 | + 'config' => $directories['app'].'/config/', |
|
| 68 | + 'resources' => $directories['app'].'/resources/', |
|
| 69 | 69 | ], |
| 70 | 70 | $directories |
| 71 | 71 | ); |
@@ -112,7 +112,7 @@ |
||
| 112 | 112 | ] |
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | - $tokenizer->addDirectory(directory('vendor') . 'spiral/validation/src/'); |
|
| 115 | + $tokenizer->addDirectory(directory('vendor').'spiral/validation/src/'); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | function () use ($container): void { |
| 32 | 32 | /** @var DatabaseManager $dbal */ |
| 33 | 33 | $dbal = $container->get(DatabaseManager::class); |
| 34 | - foreach ($dbal->getDrivers() as $driver) { |
|
| 34 | + foreach ($dbal->getDrivers() as $driver){ |
|
| 35 | 35 | $driver->disconnect(); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | function () use ($container): void { |
| 32 | 32 | /** @var DatabaseManager $dbal */ |
| 33 | 33 | $dbal = $container->get(DatabaseManager::class); |
| 34 | - foreach ($dbal->getDrivers() as $driver) { |
|
| 34 | + foreach ($dbal->getDrivers() as $driver) |
|
| 35 | + { |
|
| 35 | 36 | $driver->disconnect(); |
| 36 | 37 | } |
| 37 | 38 | } |
@@ -42,8 +42,8 @@ |
||
| 42 | 42 | EnvironmentInterface $env, |
| 43 | 43 | DirectoriesInterface $dirs |
| 44 | 44 | ): void { |
| 45 | - if (!$dirs->has('migrations')) { |
|
| 46 | - $dirs->set('migrations', $dirs->get('app') . 'migrations'); |
|
| 45 | + if (!$dirs->has('migrations')){ |
|
| 46 | + $dirs->set('migrations', $dirs->get('app').'migrations'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $config->setDefaults( |