@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function perform(FilesInterface $files): void |
30 | 30 | { |
31 | - if (!$this->verifyConfigured()) { |
|
31 | + if (!$this->verifyConfigured()){ |
|
32 | 32 | return; |
33 | 33 | } |
34 | 34 | |
35 | - if (empty($this->migrator->getMigrations())) { |
|
35 | + if (empty($this->migrator->getMigrations())){ |
|
36 | 36 | $this->writeln('<comment>No migrations were found.</comment>'); |
37 | 37 | |
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | 41 | $table = $this->table(['Migration', 'Created at', 'Executed at']); |
42 | - foreach ($this->migrator->getMigrations() as $migration) { |
|
42 | + foreach ($this->migrator->getMigrations() as $migration){ |
|
43 | 43 | $state = $migration->getState(); |
44 | 44 | |
45 | 45 | $table->addRow( |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $state->getTimeCreated()->format('Y-m-d H:i:s'), |
49 | 49 | $state->getStatus() == State::STATUS_PENDING |
50 | 50 | ? self::PENDING |
51 | - : '<info>' . $state->getTimeExecuted()->format('Y-m-d H:i:s') . '</info>' |
|
51 | + : '<info>'.$state->getTimeExecuted()->format('Y-m-d H:i:s').'</info>' |
|
52 | 52 | ] |
53 | 53 | ); |
54 | 54 | } |
@@ -28,18 +28,21 @@ |
||
28 | 28 | */ |
29 | 29 | public function perform(FilesInterface $files): void |
30 | 30 | { |
31 | - if (!$this->verifyConfigured()) { |
|
31 | + if (!$this->verifyConfigured()) |
|
32 | + { |
|
32 | 33 | return; |
33 | 34 | } |
34 | 35 | |
35 | - if (empty($this->migrator->getMigrations())) { |
|
36 | + if (empty($this->migrator->getMigrations())) |
|
37 | + { |
|
36 | 38 | $this->writeln('<comment>No migrations were found.</comment>'); |
37 | 39 | |
38 | 40 | return; |
39 | 41 | } |
40 | 42 | |
41 | 43 | $table = $this->table(['Migration', 'Created at', 'Executed at']); |
42 | - foreach ($this->migrator->getMigrations() as $migration) { |
|
44 | + foreach ($this->migrator->getMigrations() as $migration) |
|
45 | + { |
|
43 | 46 | $state = $migration->getState(); |
44 | 47 | |
45 | 48 | $table->addRow( |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | { |
27 | 27 | $services = $locator->getServices(); |
28 | 28 | |
29 | - if ($services === []) { |
|
29 | + if ($services === []){ |
|
30 | 30 | $this->writeln('<comment>No GRPC services were found.</comment>'); |
31 | 31 | return; |
32 | 32 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | ] |
40 | 40 | ); |
41 | 41 | |
42 | - foreach ($services as $interface => $instance) { |
|
42 | + foreach ($services as $interface => $instance){ |
|
43 | 43 | $grid->addRow( |
44 | 44 | [ |
45 | 45 | $interface::NAME, |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | { |
27 | 27 | $services = $locator->getServices(); |
28 | 28 | |
29 | - if ($services === []) { |
|
29 | + if ($services === []) |
|
30 | + { |
|
30 | 31 | $this->writeln('<comment>No GRPC services were found.</comment>'); |
31 | 32 | return; |
32 | 33 | } |
@@ -39,7 +40,8 @@ discard block |
||
39 | 40 | ] |
40 | 41 | ); |
41 | 42 | |
42 | - foreach ($services as $interface => $instance) { |
|
43 | + foreach ($services as $interface => $instance) |
|
44 | + { |
|
43 | 45 | $grid->addRow( |
44 | 46 | [ |
45 | 47 | $interface::NAME, |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)){ |
|
56 | 56 | throw new ControllerException( |
57 | 57 | sprintf( |
58 | 58 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | private function getPermissions(string $controller, string $action): ?array |
80 | 80 | { |
81 | 81 | $key = sprintf('%s:%s', $controller, $action); |
82 | - if (array_key_exists($key, $this->cache)) { |
|
82 | + if (array_key_exists($key, $this->cache)){ |
|
83 | 83 | return $this->cache[$key]; |
84 | 84 | } |
85 | 85 | |
86 | 86 | $this->cache[$key] = null; |
87 | - try { |
|
87 | + try{ |
|
88 | 88 | $method = new \ReflectionMethod($controller, $action); |
89 | - } catch (\ReflectionException $e) { |
|
89 | + }catch (\ReflectionException $e){ |
|
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | Guarded::class |
105 | 105 | ); |
106 | 106 | |
107 | - if ($action === null) { |
|
107 | + if ($action === null){ |
|
108 | 108 | return null; |
109 | 109 | } |
110 | 110 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ControllerException::FORBIDDEN |
127 | 127 | ]; |
128 | 128 | |
129 | - if ($guarded->permission === null && $ns === null) { |
|
129 | + if ($guarded->permission === null && $ns === null){ |
|
130 | 130 | throw new InterceptorException( |
131 | 131 | sprintf( |
132 | 132 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
@@ -136,16 +136,16 @@ discard block |
||
136 | 136 | ); |
137 | 137 | } |
138 | 138 | |
139 | - if ($ns !== null) { |
|
139 | + if ($ns !== null){ |
|
140 | 140 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
141 | 141 | } |
142 | 142 | |
143 | - if ($this->namespace !== null) { |
|
143 | + if ($this->namespace !== null){ |
|
144 | 144 | // global namespace |
145 | 145 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
146 | 146 | } |
147 | 147 | |
148 | - switch ($guarded->else) { |
|
148 | + switch ($guarded->else){ |
|
149 | 149 | case 'badAction': |
150 | 150 | $permission[1] = ControllerException::BAD_ACTION; |
151 | 151 | break; |
@@ -52,7 +52,8 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) |
|
56 | + { |
|
56 | 57 | throw new ControllerException( |
57 | 58 | sprintf( |
58 | 59 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -79,14 +80,18 @@ discard block |
||
79 | 80 | private function getPermissions(string $controller, string $action): ?array |
80 | 81 | { |
81 | 82 | $key = sprintf('%s:%s', $controller, $action); |
82 | - if (array_key_exists($key, $this->cache)) { |
|
83 | + if (array_key_exists($key, $this->cache)) |
|
84 | + { |
|
83 | 85 | return $this->cache[$key]; |
84 | 86 | } |
85 | 87 | |
86 | 88 | $this->cache[$key] = null; |
87 | - try { |
|
89 | + try |
|
90 | + { |
|
88 | 91 | $method = new \ReflectionMethod($controller, $action); |
89 | - } catch (\ReflectionException $e) { |
|
92 | + } |
|
93 | + catch (\ReflectionException $e) |
|
94 | + { |
|
90 | 95 | return null; |
91 | 96 | } |
92 | 97 | |
@@ -104,7 +109,8 @@ discard block |
||
104 | 109 | Guarded::class |
105 | 110 | ); |
106 | 111 | |
107 | - if ($action === null) { |
|
112 | + if ($action === null) |
|
113 | + { |
|
108 | 114 | return null; |
109 | 115 | } |
110 | 116 | |
@@ -126,7 +132,8 @@ discard block |
||
126 | 132 | ControllerException::FORBIDDEN |
127 | 133 | ]; |
128 | 134 | |
129 | - if ($guarded->permission === null && $ns === null) { |
|
135 | + if ($guarded->permission === null && $ns === null) |
|
136 | + { |
|
130 | 137 | throw new InterceptorException( |
131 | 138 | sprintf( |
132 | 139 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
@@ -136,16 +143,19 @@ discard block |
||
136 | 143 | ); |
137 | 144 | } |
138 | 145 | |
139 | - if ($ns !== null) { |
|
146 | + if ($ns !== null) |
|
147 | + { |
|
140 | 148 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
141 | 149 | } |
142 | 150 | |
143 | - if ($this->namespace !== null) { |
|
151 | + if ($this->namespace !== null) |
|
152 | + { |
|
144 | 153 | // global namespace |
145 | 154 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
146 | 155 | } |
147 | 156 | |
148 | - switch ($guarded->else) { |
|
157 | + switch ($guarded->else) |
|
158 | + { |
|
149 | 159 | case 'badAction': |
150 | 160 | $permission[1] = ControllerException::BAD_ACTION; |
151 | 161 | break; |
@@ -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; |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | $worker = $this->container->get(Worker::class); |
70 | 70 | $locator = $this->container->get(LocatorInterface::class); |
71 | 71 | |
72 | - foreach ($locator->getServices() as $interface => $service) { |
|
72 | + foreach ($locator->getServices() as $interface => $service){ |
|
73 | 73 | $server->registerService($interface, $service); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $server->serve( |
77 | 77 | $worker, |
78 | 78 | function (\Throwable $e = null): void { |
79 | - if ($e !== null) { |
|
79 | + if ($e !== null){ |
|
80 | 80 | $this->handleException($e); |
81 | 81 | } |
82 | 82 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function handleException(\Throwable $e): void |
92 | 92 | { |
93 | - try { |
|
93 | + try{ |
|
94 | 94 | $this->container->get(SnapshotterInterface::class)->register($e); |
95 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
95 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
96 | 96 | // no need to notify when unable to register an exception |
97 | 97 | } |
98 | 98 | } |
@@ -69,14 +69,16 @@ discard block |
||
69 | 69 | $worker = $this->container->get(Worker::class); |
70 | 70 | $locator = $this->container->get(LocatorInterface::class); |
71 | 71 | |
72 | - foreach ($locator->getServices() as $interface => $service) { |
|
72 | + foreach ($locator->getServices() as $interface => $service) |
|
73 | + { |
|
73 | 74 | $server->registerService($interface, $service); |
74 | 75 | } |
75 | 76 | |
76 | 77 | $server->serve( |
77 | 78 | $worker, |
78 | 79 | function (\Throwable $e = null): void { |
79 | - if ($e !== null) { |
|
80 | + if ($e !== null) |
|
81 | + { |
|
80 | 82 | $this->handleException($e); |
81 | 83 | } |
82 | 84 | |
@@ -90,9 +92,12 @@ discard block |
||
90 | 92 | */ |
91 | 93 | protected function handleException(\Throwable $e): void |
92 | 94 | { |
93 | - try { |
|
95 | + try |
|
96 | + { |
|
94 | 97 | $this->container->get(SnapshotterInterface::class)->register($e); |
95 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
98 | + } |
|
99 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
100 | + { |
|
96 | 101 | // no need to notify when unable to register an exception |
97 | 102 | } |
98 | 103 | } |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | |
64 | 64 | $output = trim(join("\n", $output), "\n ,"); |
65 | 65 | |
66 | - if ($output !== '') { |
|
66 | + if ($output !== ''){ |
|
67 | 67 | $this->files->deleteDirectory($tmpDir); |
68 | 68 | throw new CompileException($output); |
69 | 69 | } |
70 | 70 | |
71 | 71 | // copying files (using relative path and namespace) |
72 | 72 | $result = []; |
73 | - foreach ($this->files->getFiles($tmpDir) as $file) { |
|
73 | + foreach ($this->files->getFiles($tmpDir) as $file){ |
|
74 | 74 | $result[] = $this->copy($tmpDir, $file); |
75 | 75 | } |
76 | 76 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | private function copy(string $tmpDir, string $file): string |
88 | 88 | { |
89 | 89 | $source = ltrim($this->files->relativePath($file, $tmpDir), '\\/'); |
90 | - if (strpos($source, $this->baseNamespace) === 0) { |
|
90 | + if (strpos($source, $this->baseNamespace) === 0){ |
|
91 | 91 | $source = ltrim(substr($source, strlen($this->baseNamespace)), '\\/'); |
92 | 92 | } |
93 | 93 | |
94 | - $target = $this->files->normalizePath($this->basePath . '/' . $source); |
|
94 | + $target = $this->files->normalizePath($this->basePath.'/'.$source); |
|
95 | 95 | |
96 | 96 | $this->files->ensureDirectory(dirname($target)); |
97 | 97 | $this->files->copy($file, $target); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | private function tmpDir(): string |
106 | 106 | { |
107 | - $directory = sys_get_temp_dir() . '/' . spl_object_hash($this); |
|
107 | + $directory = sys_get_temp_dir().'/'.spl_object_hash($this); |
|
108 | 108 | $this->files->ensureDirectory($directory); |
109 | 109 | |
110 | 110 | return $this->files->normalizePath($directory, true); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | return array_filter( |
122 | 122 | $this->files->getFiles(dirname($protoFile)), |
123 | - function ($file) { |
|
123 | + function ($file){ |
|
124 | 124 | return strpos($file, '.proto') !== false; |
125 | 125 | } |
126 | 126 | ); |
@@ -63,14 +63,16 @@ discard block |
||
63 | 63 | |
64 | 64 | $output = trim(join("\n", $output), "\n ,"); |
65 | 65 | |
66 | - if ($output !== '') { |
|
66 | + if ($output !== '') |
|
67 | + { |
|
67 | 68 | $this->files->deleteDirectory($tmpDir); |
68 | 69 | throw new CompileException($output); |
69 | 70 | } |
70 | 71 | |
71 | 72 | // copying files (using relative path and namespace) |
72 | 73 | $result = []; |
73 | - foreach ($this->files->getFiles($tmpDir) as $file) { |
|
74 | + foreach ($this->files->getFiles($tmpDir) as $file) |
|
75 | + { |
|
74 | 76 | $result[] = $this->copy($tmpDir, $file); |
75 | 77 | } |
76 | 78 | |
@@ -87,7 +89,8 @@ discard block |
||
87 | 89 | private function copy(string $tmpDir, string $file): string |
88 | 90 | { |
89 | 91 | $source = ltrim($this->files->relativePath($file, $tmpDir), '\\/'); |
90 | - if (strpos($source, $this->baseNamespace) === 0) { |
|
92 | + if (strpos($source, $this->baseNamespace) === 0) |
|
93 | + { |
|
91 | 94 | $source = ltrim(substr($source, strlen($this->baseNamespace)), '\\/'); |
92 | 95 | } |
93 | 96 | |
@@ -120,7 +123,8 @@ discard block |
||
120 | 123 | { |
121 | 124 | return array_filter( |
122 | 125 | $this->files->getFiles(dirname($protoFile)), |
123 | - function ($file) { |
|
126 | + function ($file) |
|
127 | + { |
|
124 | 128 | return strpos($file, '.proto') !== false; |
125 | 129 | } |
126 | 130 | ); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use Spiral\Core\Container\Autowire; |
13 | 13 | use Spiral\Debug\Dumper; |
14 | 14 | |
15 | -if (!function_exists('bind')) { |
|
15 | +if (!function_exists('bind')){ |
|
16 | 16 | /** |
17 | 17 | * Shortcut to container Autowire definition. |
18 | 18 | * |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | -if (!function_exists('dumprr')) { |
|
33 | +if (!function_exists('dumprr')){ |
|
34 | 34 | /** |
35 | 35 | * Dumprr is similar to Dump function but always redirect output to STDERR. |
36 | 36 | * |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | use Spiral\Core\Container\Autowire; |
13 | 13 | use Spiral\Debug\Dumper; |
14 | 14 | |
15 | -if (!function_exists('bind')) { |
|
15 | +if (!function_exists('bind')) |
|
16 | +{ |
|
16 | 17 | /** |
17 | 18 | * Shortcut to container Autowire definition. |
18 | 19 | * |
@@ -30,7 +31,8 @@ discard block |
||
30 | 31 | } |
31 | 32 | } |
32 | 33 | |
33 | -if (!function_exists('dumprr')) { |
|
34 | +if (!function_exists('dumprr')) |
|
35 | +{ |
|
34 | 36 | /** |
35 | 37 | * Dumprr is similar to Dump function but always redirect output to STDERR. |
36 | 38 | * |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function load(string $id): ?TokenInterface |
48 | 48 | { |
49 | - if (strpos($id, ':') === false) { |
|
49 | + if (strpos($id, ':') === false){ |
|
50 | 50 | return null; |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** @var Token $token */ |
56 | 56 | $token = $this->orm->getRepository(Token::class)->findByPK($pk); |
57 | 57 | |
58 | - if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) { |
|
58 | + if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))){ |
|
59 | 59 | // hijacked or deleted |
60 | 60 | return null; |
61 | 61 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $token->setSecretValue($hash); |
64 | 64 | |
65 | 65 | $expiresAt = $token->getExpiresAt(); |
66 | - if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) { |
|
66 | + if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()){ |
|
67 | 67 | $this->delete($token); |
68 | 68 | return null; |
69 | 69 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function create(array $payload, DateTimeInterface $expiresAt = null): TokenInterface |
78 | 78 | { |
79 | - try { |
|
79 | + try{ |
|
80 | 80 | $token = new Token( |
81 | 81 | $this->issueID(), |
82 | 82 | $this->randomHash(128), |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->em->run(); |
90 | 90 | |
91 | 91 | return $token; |
92 | - } catch (Throwable $e) { |
|
92 | + }catch (Throwable $e){ |
|
93 | 93 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
94 | 94 | } |
95 | 95 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function delete(TokenInterface $token): void |
101 | 101 | { |
102 | - try { |
|
102 | + try{ |
|
103 | 103 | $this->em->delete($token); |
104 | 104 | $this->em->run(); |
105 | - } catch (Throwable $e) { |
|
105 | + }catch (Throwable $e){ |
|
106 | 106 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
107 | 107 | } |
108 | 108 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ->select() |
123 | 123 | ->from($this->orm->getSource(Token::class)->getTable()); |
124 | 124 | |
125 | - while ((clone $query)->where('id', $id)->count('id') !== 0) { |
|
125 | + while ((clone $query)->where('id', $id)->count('id') !== 0){ |
|
126 | 126 | $id = $this->randomHash(64); |
127 | 127 | } |
128 | 128 |
@@ -46,7 +46,8 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function load(string $id): ?TokenInterface |
48 | 48 | { |
49 | - if (strpos($id, ':') === false) { |
|
49 | + if (strpos($id, ':') === false) |
|
50 | + { |
|
50 | 51 | return null; |
51 | 52 | } |
52 | 53 | |
@@ -55,7 +56,8 @@ discard block |
||
55 | 56 | /** @var Token $token */ |
56 | 57 | $token = $this->orm->getRepository(Token::class)->findByPK($pk); |
57 | 58 | |
58 | - if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) { |
|
59 | + if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) |
|
60 | + { |
|
59 | 61 | // hijacked or deleted |
60 | 62 | return null; |
61 | 63 | } |
@@ -63,7 +65,8 @@ discard block |
||
63 | 65 | $token->setSecretValue($hash); |
64 | 66 | |
65 | 67 | $expiresAt = $token->getExpiresAt(); |
66 | - if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) { |
|
68 | + if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) |
|
69 | + { |
|
67 | 70 | $this->delete($token); |
68 | 71 | return null; |
69 | 72 | } |
@@ -76,7 +79,8 @@ discard block |
||
76 | 79 | */ |
77 | 80 | public function create(array $payload, DateTimeInterface $expiresAt = null): TokenInterface |
78 | 81 | { |
79 | - try { |
|
82 | + try |
|
83 | + { |
|
80 | 84 | $token = new Token( |
81 | 85 | $this->issueID(), |
82 | 86 | $this->randomHash(128), |
@@ -89,7 +93,9 @@ discard block |
||
89 | 93 | $this->em->run(); |
90 | 94 | |
91 | 95 | return $token; |
92 | - } catch (Throwable $e) { |
|
96 | + } |
|
97 | + catch (Throwable $e) |
|
98 | + { |
|
93 | 99 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
94 | 100 | } |
95 | 101 | } |
@@ -99,10 +105,13 @@ discard block |
||
99 | 105 | */ |
100 | 106 | public function delete(TokenInterface $token): void |
101 | 107 | { |
102 | - try { |
|
108 | + try |
|
109 | + { |
|
103 | 110 | $this->em->delete($token); |
104 | 111 | $this->em->run(); |
105 | - } catch (Throwable $e) { |
|
112 | + } |
|
113 | + catch (Throwable $e) |
|
114 | + { |
|
106 | 115 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
107 | 116 | } |
108 | 117 | } |
@@ -122,7 +131,8 @@ discard block |
||
122 | 131 | ->select() |
123 | 132 | ->from($this->orm->getSource(Token::class)->getTable()); |
124 | 133 | |
125 | - while ((clone $query)->where('id', $id)->count('id') !== 0) { |
|
134 | + while ((clone $query)->where('id', $id)->count('id') !== 0) |
|
135 | + { |
|
126 | 136 | $id = $this->randomHash(64); |
127 | 137 | } |
128 | 138 |
@@ -51,7 +51,7 @@ |
||
51 | 51 | array $payload, |
52 | 52 | DateTimeInterface $createdAt, |
53 | 53 | DateTimeInterface $expiresAt = null |
54 | - ) { |
|
54 | + ){ |
|
55 | 55 | $this->id = $id; |
56 | 56 | |
57 | 57 | $this->secretValue = $secretValue; |
@@ -43,23 +43,23 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function load(string $id): ?TokenInterface |
45 | 45 | { |
46 | - try { |
|
46 | + try{ |
|
47 | 47 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
48 | - if ($tokenData === null) { |
|
48 | + if ($tokenData === null){ |
|
49 | 49 | return null; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $token = Token::unpack($tokenData); |
53 | - } catch (Throwable $e) { |
|
53 | + }catch (Throwable $e){ |
|
54 | 54 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
55 | 55 | } |
56 | 56 | |
57 | - if (!hash_equals($token->getID(), $id)) { |
|
57 | + if (!hash_equals($token->getID(), $id)){ |
|
58 | 58 | return null; |
59 | 59 | } |
60 | 60 | |
61 | 61 | $expiresAt = $token->getExpiresAt(); |
62 | - if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) { |
|
62 | + if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()){ |
|
63 | 63 | $this->delete($token); |
64 | 64 | return null; |
65 | 65 | } |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function create(array $payload, DateTimeInterface $expiresAt = null): TokenInterface |
74 | 74 | { |
75 | - try { |
|
75 | + try{ |
|
76 | 76 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
77 | 77 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
78 | 78 | |
79 | 79 | return $token; |
80 | - } catch (Throwable $e) { |
|
80 | + }catch (Throwable $e){ |
|
81 | 81 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
82 | 82 | } |
83 | 83 | } |
@@ -43,23 +43,29 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function load(string $id): ?TokenInterface |
45 | 45 | { |
46 | - try { |
|
46 | + try |
|
47 | + { |
|
47 | 48 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
48 | - if ($tokenData === null) { |
|
49 | + if ($tokenData === null) |
|
50 | + { |
|
49 | 51 | return null; |
50 | 52 | } |
51 | 53 | |
52 | 54 | $token = Token::unpack($tokenData); |
53 | - } catch (Throwable $e) { |
|
55 | + } |
|
56 | + catch (Throwable $e) |
|
57 | + { |
|
54 | 58 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
55 | 59 | } |
56 | 60 | |
57 | - if (!hash_equals($token->getID(), $id)) { |
|
61 | + if (!hash_equals($token->getID(), $id)) |
|
62 | + { |
|
58 | 63 | return null; |
59 | 64 | } |
60 | 65 | |
61 | 66 | $expiresAt = $token->getExpiresAt(); |
62 | - if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) { |
|
67 | + if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) |
|
68 | + { |
|
63 | 69 | $this->delete($token); |
64 | 70 | return null; |
65 | 71 | } |
@@ -72,12 +78,15 @@ discard block |
||
72 | 78 | */ |
73 | 79 | public function create(array $payload, DateTimeInterface $expiresAt = null): TokenInterface |
74 | 80 | { |
75 | - try { |
|
81 | + try |
|
82 | + { |
|
76 | 83 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
77 | 84 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
78 | 85 | |
79 | 86 | return $token; |
80 | - } catch (Throwable $e) { |
|
87 | + } |
|
88 | + catch (Throwable $e) |
|
89 | + { |
|
81 | 90 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
82 | 91 | } |
83 | 92 | } |