@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | use Spiral\Framework\EnvironmentInterface; |
15 | 15 | use Spiral\Framework\Exceptions\DirectoryException; |
16 | 16 | |
17 | -if (!function_exists('bind')) { |
|
17 | +if (!function_exists('bind')) |
|
18 | +{ |
|
18 | 19 | /** |
19 | 20 | * Shortcut for new Autowire(). |
20 | 21 | * |
@@ -29,7 +30,8 @@ discard block |
||
29 | 30 | } |
30 | 31 | } |
31 | 32 | |
32 | -if (!function_exists('spiral')) { |
|
33 | +if (!function_exists('spiral')) |
|
34 | +{ |
|
33 | 35 | /** |
34 | 36 | * Resolve given alias in current IoC scope. |
35 | 37 | * |
@@ -40,19 +42,24 @@ discard block |
||
40 | 42 | */ |
41 | 43 | function spiral(string $alias) |
42 | 44 | { |
43 | - if (ContainerScope::getContainer() === null) { |
|
45 | + if (ContainerScope::getContainer() === null) |
|
46 | + { |
|
44 | 47 | throw new ScopeException('Container scope was not set.'); |
45 | 48 | } |
46 | 49 | |
47 | - try { |
|
50 | + try |
|
51 | + { |
|
48 | 52 | return ContainerScope::getContainer()->get($alias); |
49 | - } catch (ContainerExceptionInterface $e) { |
|
53 | + } |
|
54 | + catch (ContainerExceptionInterface $e) |
|
55 | + { |
|
50 | 56 | throw new ScopeException($e->getMessage(), $e->getCode(), $e); |
51 | 57 | } |
52 | 58 | } |
53 | 59 | } |
54 | 60 | |
55 | -if (!function_exists('directory')) { |
|
61 | +if (!function_exists('directory')) |
|
62 | +{ |
|
56 | 63 | /** |
57 | 64 | * Get directory alias value. |
58 | 65 | * |
@@ -69,7 +76,8 @@ discard block |
||
69 | 76 | } |
70 | 77 | } |
71 | 78 | |
72 | -if (!function_exists('env')) { |
|
79 | +if (!function_exists('env')) |
|
80 | +{ |
|
73 | 81 | /** |
74 | 82 | * Gets the value of an environment variable. |
75 | 83 | * |
@@ -84,7 +92,8 @@ discard block |
||
84 | 92 | } |
85 | 93 | } |
86 | 94 | |
87 | -if (!function_exists('e')) { |
|
95 | +if (!function_exists('e')) |
|
96 | +{ |
|
88 | 97 | /** |
89 | 98 | * Short alias for htmlentities(). This function is identical to htmlspecialchars() in all ways, |
90 | 99 | * except with htmlentities(), all characters which have HTML character entity equivalents are |
@@ -96,7 +105,8 @@ discard block |
||
96 | 105 | */ |
97 | 106 | function e(string $string = null): string |
98 | 107 | { |
99 | - if (is_null($string)) { |
|
108 | + if (is_null($string)) |
|
109 | + { |
|
100 | 110 | return ''; |
101 | 111 | } |
102 | 112 |
@@ -44,13 +44,17 @@ |
||
44 | 44 | { |
45 | 45 | $filename = $this->getFilename($section); |
46 | 46 | |
47 | - if (!file_exists($filename)) { |
|
47 | + if (!file_exists($filename)) |
|
48 | + { |
|
48 | 49 | return null; |
49 | 50 | } |
50 | 51 | |
51 | - try { |
|
52 | + try |
|
53 | + { |
|
52 | 54 | return include($filename); |
53 | - } catch (\Throwable $e) { |
|
55 | + } |
|
56 | + catch (\Throwable $e) |
|
57 | + { |
|
54 | 58 | return null; |
55 | 59 | } |
56 | 60 | } |
@@ -80,9 +80,12 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function serve() |
82 | 82 | { |
83 | - foreach ($this->dispatchers as $dispatcher) { |
|
84 | - if ($dispatcher->canServe()) { |
|
85 | - ContainerScope::runScope($this->container, function () use ($dispatcher) { |
|
83 | + foreach ($this->dispatchers as $dispatcher) |
|
84 | + { |
|
85 | + if ($dispatcher->canServe()) |
|
86 | + { |
|
87 | + ContainerScope::runScope($this->container, function () use ($dispatcher) |
|
88 | + { |
|
86 | 89 | $dispatcher->serve(); |
87 | 90 | }); |
88 | 91 | return; |
@@ -105,11 +108,13 @@ discard block |
||
105 | 108 | */ |
106 | 109 | protected function mapDirectories(array $directories): array |
107 | 110 | { |
108 | - if (!isset($directories['root'])) { |
|
111 | + if (!isset($directories['root'])) |
|
112 | + { |
|
109 | 113 | throw new FrameworkException("Missing required directory `root`."); |
110 | 114 | } |
111 | 115 | |
112 | - if (!isset($directories['app'])) { |
|
116 | + if (!isset($directories['app'])) |
|
117 | + { |
|
113 | 118 | $directories['app'] = $directories['root'] . '/app/'; |
114 | 119 | } |
115 | 120 | |
@@ -152,7 +157,8 @@ discard block |
||
152 | 157 | EnvironmentInterface $environment = null, |
153 | 158 | bool $handleErrors = true |
154 | 159 | ): self { |
155 | - if ($handleErrors) { |
|
160 | + if ($handleErrors) |
|
161 | + { |
|
156 | 162 | ExceptionHandler::register(); |
157 | 163 | } |
158 | 164 | |
@@ -162,11 +168,15 @@ discard block |
||
162 | 168 | $environment ?? new Environment() |
163 | 169 | ); |
164 | 170 | |
165 | - try { |
|
166 | - ContainerScope::runScope($core->container, function () use ($core) { |
|
171 | + try |
|
172 | + { |
|
173 | + ContainerScope::runScope($core->container, function () use ($core) |
|
174 | + { |
|
167 | 175 | $core->bootload()->bootstrap(); |
168 | 176 | }); |
169 | - } catch (\Throwable $e) { |
|
177 | + } |
|
178 | + catch (\Throwable $e) |
|
179 | + { |
|
170 | 180 | ExceptionHandler::handleException($e); |
171 | 181 | } |
172 | 182 |
@@ -35,7 +35,8 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public static function handleShutdown() |
37 | 37 | { |
38 | - if (!empty($error = error_get_last())) { |
|
38 | + if (!empty($error = error_get_last())) |
|
39 | + { |
|
39 | 40 | self::handleException( |
40 | 41 | new FatalException($error['message'], $error['type'], 0, $error['file'], $error['line']) |
41 | 42 | ); |
@@ -64,9 +65,12 @@ discard block |
||
64 | 65 | */ |
65 | 66 | public static function handleException(\Throwable $e) |
66 | 67 | { |
67 | - if (php_sapi_name() == 'cli') { |
|
68 | + if (php_sapi_name() == 'cli') |
|
69 | + { |
|
68 | 70 | $handler = new ConsoleHandler(STDERR); |
69 | - } else { |
|
71 | + } |
|
72 | + else |
|
73 | + { |
|
70 | 74 | $handler = new HtmlHandler(HtmlHandler::INVERTED); |
71 | 75 | } |
72 | 76 |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getID(): string |
41 | 41 | { |
42 | - if (empty($this->id)) { |
|
42 | + if (empty($this->id)) |
|
43 | + { |
|
43 | 44 | $this->id = md5(serialize($this->values)); |
44 | 45 | } |
45 | 46 | |
@@ -62,7 +63,8 @@ discard block |
||
62 | 63 | */ |
63 | 64 | public function get(string $name, $default = null) |
64 | 65 | { |
65 | - if (isset($this->values[$name])) { |
|
66 | + if (isset($this->values[$name])) |
|
67 | + { |
|
66 | 68 | return $this->normalize($this->values[$name]); |
67 | 69 | } |
68 | 70 | |
@@ -75,12 +77,14 @@ discard block |
||
75 | 77 | */ |
76 | 78 | protected function normalize($value): ?string |
77 | 79 | { |
78 | - if (!is_string($value)) { |
|
80 | + if (!is_string($value)) |
|
81 | + { |
|
79 | 82 | return $value; |
80 | 83 | } |
81 | 84 | |
82 | 85 | $alias = strtolower($value); |
83 | - if (isset(self::VALUE_MAP[$alias])) { |
|
86 | + if (isset(self::VALUE_MAP[$alias])) |
|
87 | + { |
|
84 | 88 | return self::VALUE_MAP[$alias]; |
85 | 89 | } |
86 | 90 |
@@ -23,7 +23,8 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct(array $directories) |
25 | 25 | { |
26 | - foreach ($directories as $name => $directory) { |
|
26 | + foreach ($directories as $name => $directory) |
|
27 | + { |
|
27 | 28 | $this->set($name, $directory); |
28 | 29 | } |
29 | 30 | } |
@@ -52,7 +53,8 @@ discard block |
||
52 | 53 | */ |
53 | 54 | public function get(string $name): string |
54 | 55 | { |
55 | - if (!$this->has($name)) { |
|
56 | + if (!$this->has($name)) |
|
57 | + { |
|
56 | 58 | throw new DirectoryException("Undefined directory '{$name}'"); |
57 | 59 | } |
58 | 60 |