@@ -36,11 +36,15 @@ |
||
36 | 36 | */ |
37 | 37 | public function loadFile(string $section, string $filename): array |
38 | 38 | { |
39 | - try { |
|
40 | - return ContainerScope::runScope($this->container, function () use ($filename) { |
|
39 | + try |
|
40 | + { |
|
41 | + return ContainerScope::runScope($this->container, function () use ($filename) |
|
42 | + { |
|
41 | 43 | return (require $filename); |
42 | 44 | }); |
43 | - } catch (\Throwable $e) { |
|
45 | + } |
|
46 | + catch (\Throwable $e) |
|
47 | + { |
|
44 | 48 | throw new LoaderException($e->getMessage(), $e->getCode(), $e); |
45 | 49 | } |
46 | 50 | } |
@@ -37,9 +37,12 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct(string $key) |
39 | 39 | { |
40 | - try { |
|
40 | + try |
|
41 | + { |
|
41 | 42 | $this->key = Key::loadFromAsciiSafeString($key); |
42 | - } catch (CryptoException $e) { |
|
43 | + } |
|
44 | + catch (CryptoException $e) |
|
45 | + { |
|
43 | 46 | throw new EncrypterException($e->getMessage(), $e->getCode(), $e); |
44 | 47 | } |
45 | 48 | } |
@@ -50,9 +53,12 @@ discard block |
||
50 | 53 | public function withKey(string $key): EncrypterInterface |
51 | 54 | { |
52 | 55 | $encrypter = clone $this; |
53 | - try { |
|
56 | + try |
|
57 | + { |
|
54 | 58 | $encrypter->key = Key::loadFromAsciiSafeString($key); |
55 | - } catch (CryptoException $e) { |
|
59 | + } |
|
60 | + catch (CryptoException $e) |
|
61 | + { |
|
56 | 62 | throw new EncrypterException($e->getMessage(), $e->getCode(), $e); |
57 | 63 | } |
58 | 64 | |
@@ -64,9 +70,12 @@ discard block |
||
64 | 70 | */ |
65 | 71 | public function getKey(): string |
66 | 72 | { |
67 | - try { |
|
73 | + try |
|
74 | + { |
|
68 | 75 | return $this->key->saveToAsciiSafeString(); |
69 | - } catch (EnvironmentIsBrokenException $e) { |
|
76 | + } |
|
77 | + catch (EnvironmentIsBrokenException $e) |
|
78 | + { |
|
70 | 79 | throw new EncrypterException($e->getMessage(), $e->getCode(), $e); |
71 | 80 | } |
72 | 81 | } |
@@ -80,9 +89,12 @@ discard block |
||
80 | 89 | { |
81 | 90 | $packed = json_encode($data); |
82 | 91 | |
83 | - try { |
|
92 | + try |
|
93 | + { |
|
84 | 94 | return base64_encode(Crypto::Encrypt($packed, $this->key)); |
85 | - } catch (\Throwable $e) { |
|
95 | + } |
|
96 | + catch (\Throwable $e) |
|
97 | + { |
|
86 | 98 | throw new EncryptException($e->getMessage(), $e->getCode(), $e); |
87 | 99 | } |
88 | 100 | } |
@@ -94,14 +106,17 @@ discard block |
||
94 | 106 | */ |
95 | 107 | public function decrypt(string $payload) |
96 | 108 | { |
97 | - try { |
|
109 | + try |
|
110 | + { |
|
98 | 111 | $result = Crypto::Decrypt( |
99 | 112 | base64_decode($payload), |
100 | 113 | $this->key |
101 | 114 | ); |
102 | 115 | |
103 | 116 | return json_decode($result, true); |
104 | - } catch (\Throwable $e) { |
|
117 | + } |
|
118 | + catch (\Throwable $e) |
|
119 | + { |
|
105 | 120 | throw new DecryptException($e->getMessage(), $e->getCode(), $e); |
106 | 121 | } |
107 | 122 | } |
@@ -56,33 +56,44 @@ |
||
56 | 56 | public function wrap(array $args): array |
57 | 57 | { |
58 | 58 | $result = []; |
59 | - foreach ($args as $arg) { |
|
59 | + foreach ($args as $arg) |
|
60 | + { |
|
60 | 61 | $display = $type = strtolower(gettype($arg)); |
61 | 62 | |
62 | - if (is_numeric($arg)) { |
|
63 | + if (is_numeric($arg)) |
|
64 | + { |
|
63 | 65 | $result[] = $this->r->apply($arg, 'value', $type); |
64 | 66 | continue; |
65 | - } elseif (is_bool($arg)) { |
|
67 | + } |
|
68 | + elseif (is_bool($arg)) |
|
69 | + { |
|
66 | 70 | $result[] = $this->r->apply($arg ? 'true' : 'false', 'value', $type); |
67 | 71 | continue; |
68 | - } elseif (is_null($arg)) { |
|
72 | + } |
|
73 | + elseif (is_null($arg)) |
|
74 | + { |
|
69 | 75 | $result[] = $this->r->apply('null', 'value', $type); |
70 | 76 | continue; |
71 | 77 | } |
72 | 78 | |
73 | - if (is_object($arg)) { |
|
79 | + if (is_object($arg)) |
|
80 | + { |
|
74 | 81 | $reflection = new \ReflectionClass($arg); |
75 | 82 | $display = sprintf('<span title="%s">%s</span>', $reflection->getName(), $reflection->getShortName()); |
76 | 83 | } |
77 | 84 | |
78 | 85 | $type = $this->r->apply($display, 'value', $type); |
79 | 86 | |
80 | - if ($this->verbosity < HandlerInterface::VERBOSITY_DEBUG) { |
|
87 | + if ($this->verbosity < HandlerInterface::VERBOSITY_DEBUG) |
|
88 | + { |
|
81 | 89 | $result[] = sprintf('<span>%s</span>', $type); |
82 | - } else { |
|
90 | + } |
|
91 | + else |
|
92 | + { |
|
83 | 93 | $hash = is_object($arg) ? spl_object_hash($arg) : md5(json_encode($arg)); |
84 | 94 | |
85 | - if (!isset($this->values[$hash])) { |
|
95 | + if (!isset($this->values[$hash])) |
|
96 | + { |
|
86 | 97 | $this->values[$hash] = $this->dumper->dump($arg, Dumper::RETURN); |
87 | 98 | } |
88 | 99 |
@@ -73,16 +73,19 @@ |
||
73 | 73 | */ |
74 | 74 | public function handle(Request $request): Response |
75 | 75 | { |
76 | - if (empty($this->handler)) { |
|
76 | + if (empty($this->handler)) |
|
77 | + { |
|
77 | 78 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
78 | 79 | } |
79 | 80 | |
80 | 81 | $position = $this->position++; |
81 | - if (isset($this->middleware[$position])) { |
|
82 | + if (isset($this->middleware[$position])) |
|
83 | + { |
|
82 | 84 | return $this->middleware[$position]->process($request, $this); |
83 | 85 | } |
84 | 86 | |
85 | - return $this->scope->runScope([Request::class => $request], function () use ($request) { |
|
87 | + return $this->scope->runScope([Request::class => $request], function () use ($request) |
|
88 | + { |
|
86 | 89 | return $this->handler->handle($request); |
87 | 90 | }); |
88 | 91 | } |
@@ -49,7 +49,8 @@ |
||
49 | 49 | { |
50 | 50 | $name = $name ?? $this->default; |
51 | 51 | |
52 | - if (!isset($this->transports[$name])) { |
|
52 | + if (!isset($this->transports[$name])) |
|
53 | + { |
|
53 | 54 | throw new TransportException("Undefined auth transport {$name}"); |
54 | 55 | } |
55 | 56 |
@@ -68,7 +68,8 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setLocale(string $locale): void |
70 | 70 | { |
71 | - if (!$this->catalogueManager->has($locale)) { |
|
71 | + if (!$this->catalogueManager->has($locale)) |
|
72 | + { |
|
72 | 73 | throw new LocaleException($locale); |
73 | 74 | } |
74 | 75 | |
@@ -128,7 +129,8 @@ discard block |
||
128 | 129 | $domain = $domain ?? $this->config->getDefaultDomain(); |
129 | 130 | $locale = $locale ?? $this->locale; |
130 | 131 | |
131 | - try { |
|
132 | + try |
|
133 | + { |
|
132 | 134 | $message = $this->get($locale, $domain, $id); |
133 | 135 | |
134 | 136 | $pluralized = $this->identityTranslator->trans( |
@@ -137,12 +139,15 @@ discard block |
||
137 | 139 | null, |
138 | 140 | $locale |
139 | 141 | ); |
140 | - } catch (\InvalidArgumentException $e) { |
|
142 | + } |
|
143 | + catch (\InvalidArgumentException $e) |
|
144 | + { |
|
141 | 145 | //Wrapping into more explanatory exception |
142 | 146 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
143 | 147 | } |
144 | 148 | |
145 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
149 | + if (empty($parameters['n']) && is_numeric($number)) |
|
150 | + { |
|
146 | 151 | $parameters['n'] = $number; |
147 | 152 | } |
148 | 153 | |
@@ -168,13 +173,18 @@ discard block |
||
168 | 173 | string $postfix = '}' |
169 | 174 | ): string { |
170 | 175 | $replaces = []; |
171 | - foreach ($values as $key => $value) { |
|
176 | + foreach ($values as $key => $value) |
|
177 | + { |
|
172 | 178 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
173 | 179 | |
174 | - if (is_object($value)) { |
|
175 | - if (method_exists($value, '__toString')) { |
|
180 | + if (is_object($value)) |
|
181 | + { |
|
182 | + if (method_exists($value, '__toString')) |
|
183 | + { |
|
176 | 184 | $value = $value->__toString(); |
177 | - } else { |
|
185 | + } |
|
186 | + else |
|
187 | + { |
|
178 | 188 | $value = ''; |
179 | 189 | } |
180 | 190 | } |
@@ -207,18 +217,21 @@ discard block |
||
207 | 217 | */ |
208 | 218 | protected function get(string &$locale, string $domain, string $string): string |
209 | 219 | { |
210 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
220 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
221 | + { |
|
211 | 222 | return $this->catalogueManager->get($locale)->get($domain, $string); |
212 | 223 | } |
213 | 224 | |
214 | 225 | $locale = $this->config->getFallbackLocale(); |
215 | 226 | |
216 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
227 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
228 | + { |
|
217 | 229 | return $this->catalogueManager->get($locale)->get($domain, $string); |
218 | 230 | } |
219 | 231 | |
220 | 232 | // we can automatically register message |
221 | - if ($this->config->isAutoRegisterMessages()) { |
|
233 | + if ($this->config->isAutoRegisterMessages()) |
|
234 | + { |
|
222 | 235 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
223 | 236 | $this->catalogueManager->save($locale); |
224 | 237 | } |
@@ -45,9 +45,12 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function callAction(string $controller, string $action, array $parameters = []) |
47 | 47 | { |
48 | - try { |
|
48 | + try |
|
49 | + { |
|
49 | 50 | $method = new \ReflectionMethod($controller, $action); |
50 | - } catch (\ReflectionException $e) { |
|
51 | + } |
|
52 | + catch (\ReflectionException $e) |
|
53 | + { |
|
51 | 54 | throw new ControllerException( |
52 | 55 | "Invalid action `{$controller}`->`{$action}`", |
53 | 56 | ControllerException::BAD_ACTION, |
@@ -55,22 +58,28 @@ discard block |
||
55 | 58 | ); |
56 | 59 | } |
57 | 60 | |
58 | - if ($method->isStatic() || !$method->isPublic()) { |
|
61 | + if ($method->isStatic() || !$method->isPublic()) |
|
62 | + { |
|
59 | 63 | throw new ControllerException( |
60 | 64 | "Invalid action `{$controller}`->`{$action}`", |
61 | 65 | ControllerException::BAD_ACTION |
62 | 66 | ); |
63 | 67 | } |
64 | 68 | |
65 | - try { |
|
69 | + try |
|
70 | + { |
|
66 | 71 | // getting the set of arguments should be sent to requested method |
67 | 72 | $args = $this->resolver->resolveArguments($method, $parameters); |
68 | - } catch (ArgumentException $e) { |
|
73 | + } |
|
74 | + catch (ArgumentException $e) |
|
75 | + { |
|
69 | 76 | throw new ControllerException( |
70 | 77 | "Missing/invalid parameter '{$e->getParameter()->name}' of `{$controller}`->`{$action}`", |
71 | 78 | ControllerException::BAD_ARGUMENT |
72 | 79 | ); |
73 | - } catch (ContainerExceptionInterface $e) { |
|
80 | + } |
|
81 | + catch (ContainerExceptionInterface $e) |
|
82 | + { |
|
74 | 83 | throw new ControllerException( |
75 | 84 | $e->getMessage(), |
76 | 85 | ControllerException::ERROR, |
@@ -78,7 +87,8 @@ discard block |
||
78 | 87 | ); |
79 | 88 | } |
80 | 89 | |
81 | - return ContainerScope::runScope($this->container, function () use ($controller, $method, $args) { |
|
90 | + return ContainerScope::runScope($this->container, function () use ($controller, $method, $args) |
|
91 | + { |
|
82 | 92 | return $method->invokeArgs($this->container->get($controller), $args); |
83 | 93 | }); |
84 | 94 | } |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | public function getGuard(): GuardInterface |
29 | 29 | { |
30 | 30 | $container = ContainerScope::getContainer(); |
31 | - if (empty($container) || !$container->has(GuardInterface::class)) { |
|
31 | + if (empty($container) || !$container->has(GuardInterface::class)) |
|
32 | + { |
|
32 | 33 | throw new ScopeException( |
33 | 34 | 'Unable to get `GuardInterface`, binding is missing or container scope is not set' |
34 | 35 | ); |
@@ -65,7 +66,8 @@ discard block |
||
65 | 66 | */ |
66 | 67 | protected function resolvePermission(string $permission): string |
67 | 68 | { |
68 | - if (defined('static::GUARD_NAMESPACE')) { |
|
69 | + if (defined('static::GUARD_NAMESPACE')) |
|
70 | + { |
|
69 | 71 | // Yay! Isolation |
70 | 72 | $permission = constant(get_called_class() . '::' . 'GUARD_NAMESPACE') . '.' . $permission; |
71 | 73 | } |
@@ -11,7 +11,8 @@ discard block |
||
11 | 11 | |
12 | 12 | use Spiral\Debug\Dumper; |
13 | 13 | |
14 | -if (!function_exists('dump')) { |
|
14 | +if (!function_exists('dump')) |
|
15 | +{ |
|
15 | 16 | /** |
16 | 17 | * Dump value. |
17 | 18 | * |
@@ -22,12 +23,14 @@ discard block |
||
22 | 23 | */ |
23 | 24 | function dump($value, int $output = Dumper::OUTPUT): ?string |
24 | 25 | { |
25 | - if (!class_exists(\Spiral\Core\ContainerScope::class)) { |
|
26 | + if (!class_exists(\Spiral\Core\ContainerScope::class)) |
|
27 | + { |
|
26 | 28 | return (new Dumper())->dump($value, $output); |
27 | 29 | } |
28 | 30 | |
29 | 31 | $container = \Spiral\Core\ContainerScope::getContainer(); |
30 | - if (is_null($container) || !$container->has(Dumper::class)) { |
|
32 | + if (is_null($container) || !$container->has(Dumper::class)) |
|
33 | + { |
|
31 | 34 | $dumper = new Dumper(); |
32 | 35 | |
33 | 36 | return $dumper->dump($value, $output); |