@@ -14,7 +14,7 @@ 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 | * Shortcut for new Autowire(). |
| 20 | 20 | * |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -if (!function_exists('spiral')) { |
|
| 32 | +if (!function_exists('spiral')){ |
|
| 33 | 33 | /** |
| 34 | 34 | * Resolve given alias in current IoC scope. |
| 35 | 35 | * |
@@ -40,19 +40,19 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function spiral(string $alias) |
| 42 | 42 | { |
| 43 | - if (ContainerScope::getContainer() === null) { |
|
| 43 | + if (ContainerScope::getContainer() === null){ |
|
| 44 | 44 | throw new ScopeException('Container scope was not set.'); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - try { |
|
| 47 | + try{ |
|
| 48 | 48 | return ContainerScope::getContainer()->get($alias); |
| 49 | - } catch (ContainerExceptionInterface $e) { |
|
| 49 | + }catch (ContainerExceptionInterface $e){ |
|
| 50 | 50 | throw new ScopeException($e->getMessage(), $e->getCode(), $e); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | -if (!function_exists('directory')) { |
|
| 55 | +if (!function_exists('directory')){ |
|
| 56 | 56 | /** |
| 57 | 57 | * Get directory alias value. |
| 58 | 58 | * |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | -if (!function_exists('env')) { |
|
| 72 | +if (!function_exists('env')){ |
|
| 73 | 73 | /** |
| 74 | 74 | * Gets the value of an environment variable. |
| 75 | 75 | * |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | -if (!function_exists('e')) { |
|
| 87 | +if (!function_exists('e')){ |
|
| 88 | 88 | /** |
| 89 | 89 | * Short alias for htmlentities(). This function is identical to htmlspecialchars() in all ways, |
| 90 | 90 | * except with htmlentities(), all characters which have HTML character entity equivalents are |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | function e(string $string = null): string |
| 98 | 98 | { |
| 99 | - if (is_null($string)) { |
|
| 99 | + if (is_null($string)){ |
|
| 100 | 100 | return ''; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -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 | |
@@ -9,4 +9,4 @@ |
||
| 9 | 9 | ini_set('display_errors', true); |
| 10 | 10 | |
| 11 | 11 | //Composer |
| 12 | -require dirname(__DIR__) . '/vendor/autoload.php'; |
|
| 13 | 12 | \ No newline at end of file |
| 13 | +require dirname(__DIR__).'/vendor/autoload.php'; |
|
| 14 | 14 | \ No newline at end of file |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | $filename = $this->getFilename($section); |
| 46 | 46 | |
| 47 | - if (!file_exists($filename)) { |
|
| 47 | + if (!file_exists($filename)){ |
|
| 48 | 48 | return null; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - try { |
|
| 51 | + try{ |
|
| 52 | 52 | return include($filename); |
| 53 | - } catch (\Throwable $e) { |
|
| 53 | + }catch (\Throwable $e){ |
|
| 54 | 54 | return null; |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $this->files->write( |
| 64 | 64 | $this->getFilename($section), |
| 65 | - '<?php return ' . var_export($data, true) . ';', |
|
| 65 | + '<?php return '.var_export($data, true).';', |
|
| 66 | 66 | FilesInterface::RUNTIME, |
| 67 | 67 | true |
| 68 | 68 | ); |
@@ -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,8 +80,8 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function serve() |
| 82 | 82 | { |
| 83 | - foreach ($this->dispatchers as $dispatcher) { |
|
| 84 | - if ($dispatcher->canServe()) { |
|
| 83 | + foreach ($this->dispatchers as $dispatcher){ |
|
| 84 | + if ($dispatcher->canServe()){ |
|
| 85 | 85 | ContainerScope::runScope($this->container, function () use ($dispatcher) { |
| 86 | 86 | $dispatcher->serve(); |
| 87 | 87 | }); |
@@ -105,25 +105,25 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | protected function mapDirectories(array $directories): array |
| 107 | 107 | { |
| 108 | - if (!isset($directories['root'])) { |
|
| 108 | + if (!isset($directories['root'])){ |
|
| 109 | 109 | throw new FrameworkException("Missing required directory `root`."); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if (!isset($directories['app'])) { |
|
| 113 | - $directories['app'] = $directories['root'] . '/app/'; |
|
| 112 | + if (!isset($directories['app'])){ |
|
| 113 | + $directories['app'] = $directories['root'].'/app/'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return array_merge($directories, [ |
| 117 | 117 | // public root |
| 118 | - 'public' => $directories['root'] . '/public/', |
|
| 118 | + 'public' => $directories['root'].'/public/', |
|
| 119 | 119 | |
| 120 | 120 | // application directories |
| 121 | - 'config' => $directories['app'] . '/config/', |
|
| 122 | - 'resources' => $directories['app'] . '/resources/', |
|
| 121 | + 'config' => $directories['app'].'/config/', |
|
| 122 | + 'resources' => $directories['app'].'/resources/', |
|
| 123 | 123 | |
| 124 | 124 | // data directories |
| 125 | - 'runtime' => $directories['app'] . '/runtime/', |
|
| 126 | - 'cache' => $directories['app'] . '/runtime/cache/', |
|
| 125 | + 'runtime' => $directories['app'].'/runtime/', |
|
| 126 | + 'cache' => $directories['app'].'/runtime/cache/', |
|
| 127 | 127 | ]); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | EnvironmentInterface $environment = null, |
| 153 | 153 | bool $handleErrors = true |
| 154 | 154 | ): self { |
| 155 | - if ($handleErrors) { |
|
| 155 | + if ($handleErrors){ |
|
| 156 | 156 | ExceptionHandler::register(); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | $environment ?? new Environment() |
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | - try { |
|
| 165 | + try{ |
|
| 166 | 166 | ContainerScope::runScope($core->container, function () use ($core) { |
| 167 | 167 | $core->bootload()->bootstrap(); |
| 168 | 168 | }); |
| 169 | - } catch (\Throwable $e) { |
|
| 169 | + }catch (\Throwable $e){ |
|
| 170 | 170 | ExceptionHandler::handleException($e); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -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,7 @@ 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 | self::handleException( |
| 40 | 40 | new FatalException($error['message'], $error['type'], 0, $error['file'], $error['line']) |
| 41 | 41 | ); |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public static function handleException(\Throwable $e) |
| 66 | 66 | { |
| 67 | - if (php_sapi_name() == 'cli') { |
|
| 67 | + if (php_sapi_name() == 'cli'){ |
|
| 68 | 68 | $handler = new ConsoleHandler(STDERR); |
| 69 | - } else { |
|
| 69 | + }else{ |
|
| 70 | 70 | $handler = new HtmlHandler(HtmlHandler::INVERTED); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -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,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function getID(): string |
| 41 | 41 | { |
| 42 | - if (empty($this->id)) { |
|
| 42 | + if (empty($this->id)){ |
|
| 43 | 43 | $this->id = md5(serialize($this->values)); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function get(string $name, $default = null) |
| 64 | 64 | { |
| 65 | - if (isset($this->values[$name])) { |
|
| 65 | + if (isset($this->values[$name])){ |
|
| 66 | 66 | return $this->normalize($this->values[$name]); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | protected function normalize($value): ?string |
| 77 | 77 | { |
| 78 | - if (!is_string($value)) { |
|
| 78 | + if (!is_string($value)){ |
|
| 79 | 79 | return $value; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $alias = strtolower($value); |
| 83 | - if (isset(self::VALUE_MAP[$alias])) { |
|
| 83 | + if (isset(self::VALUE_MAP[$alias])){ |
|
| 84 | 84 | return self::VALUE_MAP[$alias]; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -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,7 @@ 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 | $this->set($name, $directory); |
| 28 | 28 | } |
| 29 | 29 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | public function set(string $name, string $path): DirectoriesInterface |
| 43 | 43 | { |
| 44 | 44 | $path = str_replace(['\\', '//'], '/', $path); |
| 45 | - $this->directories[$name] = rtrim($path, '/') . '/'; |
|
| 45 | + $this->directories[$name] = rtrim($path, '/').'/'; |
|
| 46 | 46 | |
| 47 | 47 | return $this; |
| 48 | 48 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function get(string $name): string |
| 54 | 54 | { |
| 55 | - if (!$this->has($name)) { |
|
| 55 | + if (!$this->has($name)){ |
|
| 56 | 56 | throw new DirectoryException("Undefined directory '{$name}'"); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -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 | |