@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $scope = self::getAccessor($container)->scope; |
| 30 | 30 | $result = []; |
| 31 | - do { |
|
| 31 | + do{ |
|
| 32 | 32 | $result[] = $scope->getScopeName(); |
| 33 | 33 | $scope = $scope->getParentScope(); |
| 34 | - } while ($scope !== null); |
|
| 34 | + }while ($scope !== null); |
|
| 35 | 35 | |
| 36 | 36 | return $result; |
| 37 | 37 | } |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | Proxy::isProxy($container) => ContainerScope::getContainer() ?? throw new \RuntimeException( |
| 47 | 47 | 'Container Proxy is out of scope.', |
| 48 | 48 | ), |
| 49 | - default => throw new \InvalidArgumentException('Container must be an instance of ' . Container::class), |
|
| 49 | + default => throw new \InvalidArgumentException('Container must be an instance of '.Container::class), |
|
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | 52 | $container ??= ContainerScope::getContainer(); |
| 53 | 53 | |
| 54 | - if (!$container instanceof Container) { |
|
| 54 | + if (!$container instanceof Container){ |
|
| 55 | 55 | throw new \RuntimeException('Container is not available.'); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -28,7 +28,8 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $scope = self::getAccessor($container)->scope; |
| 30 | 30 | $result = []; |
| 31 | - do { |
|
| 31 | + do |
|
| 32 | + { |
|
| 32 | 33 | $result[] = $scope->getScopeName(); |
| 33 | 34 | $scope = $scope->getParentScope(); |
| 34 | 35 | } while ($scope !== null); |
@@ -51,7 +52,8 @@ discard block |
||
| 51 | 52 | |
| 52 | 53 | $container ??= ContainerScope::getContainer(); |
| 53 | 54 | |
| 54 | - if (!$container instanceof Container) { |
|
| 55 | + if (!$container instanceof Container) |
|
| 56 | + { |
|
| 55 | 57 | throw new \RuntimeException('Container is not available.'); |
| 56 | 58 | } |
| 57 | 59 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | #[Proxy] private readonly ContainerInterface $container, |
| 123 | 123 | /** @invisible */ |
| 124 | 124 | HttpConfig $config = new HttpConfig() |
| 125 | - ) { |
|
| 125 | + ){ |
|
| 126 | 126 | $this->bagAssociations = \array_merge($this->bagAssociations, $config->getInputBags()); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $input = clone $this; |
| 153 | 153 | |
| 154 | - if ($add) { |
|
| 155 | - $input->prefix .= '.' . $prefix; |
|
| 154 | + if ($add){ |
|
| 155 | + $input->prefix .= '.'.$prefix; |
|
| 156 | 156 | $input->prefix = \trim($input->prefix, '.'); |
| 157 | - } else { |
|
| 157 | + }else{ |
|
| 158 | 158 | $input->prefix = $prefix; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | return match (true) { |
| 172 | 172 | empty($path) => '/', |
| 173 | - $path[0] !== '/' => '/' . $path, |
|
| 173 | + $path[0] !== '/' => '/'.$path, |
|
| 174 | 174 | default => $path |
| 175 | 175 | }; |
| 176 | 176 | } |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function request(): Request |
| 192 | 192 | { |
| 193 | - try { |
|
| 193 | + try{ |
|
| 194 | 194 | $request = $this->container->get(Request::class); |
| 195 | - } catch (ContainerExceptionInterface $e) { |
|
| 195 | + }catch (ContainerExceptionInterface $e){ |
|
| 196 | 196 | $scope = implode('.', \array_reverse(Introspector::scopeNames($this->container))); |
| 197 | 197 | throw new ScopeException( |
| 198 | 198 | "Unable to get `ServerRequestInterface` in the `$scope` container scope", |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Flushing input state |
| 205 | - if ($this->request !== $request) { |
|
| 205 | + if ($this->request !== $request){ |
|
| 206 | 206 | $this->bags = []; |
| 207 | 207 | $this->request = $request; |
| 208 | 208 | } |
@@ -215,11 +215,11 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | public function bearerToken(): ?string |
| 217 | 217 | { |
| 218 | - $header = (string) $this->header('Authorization', ''); |
|
| 218 | + $header = (string)$this->header('Authorization', ''); |
|
| 219 | 219 | |
| 220 | 220 | $position = \strrpos($header, 'Bearer '); |
| 221 | 221 | |
| 222 | - if ($position !== false) { |
|
| 222 | + if ($position !== false){ |
|
| 223 | 223 | $header = \substr($header, $position + 7); |
| 224 | 224 | |
| 225 | 225 | return \str_contains($header, ',') |
@@ -273,16 +273,16 @@ discard block |
||
| 273 | 273 | public function isJsonExpected(bool $softMatch = false): bool |
| 274 | 274 | { |
| 275 | 275 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 276 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 277 | - if ($acceptHeader->has($jsonType)) { |
|
| 276 | + foreach ($this->jsonTypes as $jsonType){ |
|
| 277 | + if ($acceptHeader->has($jsonType)){ |
|
| 278 | 278 | return true; |
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if ($softMatch) { |
|
| 283 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 284 | - $itemValue = \strtolower((string) $item->getValue()); |
|
| 285 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
| 282 | + if ($softMatch){ |
|
| 283 | + foreach ($acceptHeader->getAll() as $item){ |
|
| 284 | + $itemValue = \strtolower((string)$item->getValue()); |
|
| 285 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')){ |
|
| 286 | 286 | return true; |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -321,19 +321,19 @@ discard block |
||
| 321 | 321 | // ensure proper request association |
| 322 | 322 | $this->request(); |
| 323 | 323 | |
| 324 | - if (isset($this->bags[$name])) { |
|
| 324 | + if (isset($this->bags[$name])){ |
|
| 325 | 325 | return $this->bags[$name]; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | $definition = $this->findBagDefinition($name); |
| 329 | - if (!$definition) { |
|
| 329 | + if (!$definition){ |
|
| 330 | 330 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | $class = $definition['class']; |
| 334 | 334 | $data = \call_user_func([$this->request(), $definition['source']]); |
| 335 | 335 | |
| 336 | - if (!\is_array($data)) { |
|
| 336 | + if (!\is_array($data)){ |
|
| 337 | 337 | $data = (array)$data; |
| 338 | 338 | } |
| 339 | 339 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | |
| 343 | 343 | public function hasBag(string $name): bool |
| 344 | 344 | { |
| 345 | - if (isset($this->bags[$name])) { |
|
| 345 | + if (isset($this->bags[$name])){ |
|
| 346 | 346 | return true; |
| 347 | 347 | } |
| 348 | 348 | |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | private function findBagDefinition(string $name): ?array |
| 364 | 364 | { |
| 365 | - if (isset($this->bagAssociations[$name])) { |
|
| 365 | + if (isset($this->bagAssociations[$name])){ |
|
| 366 | 366 | return $this->bagAssociations[$name]; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - foreach ($this->bagAssociations as $bag) { |
|
| 370 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
| 369 | + foreach ($this->bagAssociations as $bag){ |
|
| 370 | + if (isset($bag['alias']) && $bag['alias'] === $name){ |
|
| 371 | 371 | return $bag; |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -151,10 +151,13 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $input = clone $this; |
| 153 | 153 | |
| 154 | - if ($add) { |
|
| 154 | + if ($add) |
|
| 155 | + { |
|
| 155 | 156 | $input->prefix .= '.' . $prefix; |
| 156 | 157 | $input->prefix = \trim($input->prefix, '.'); |
| 157 | - } else { |
|
| 158 | + } |
|
| 159 | + else |
|
| 160 | + { |
|
| 158 | 161 | $input->prefix = $prefix; |
| 159 | 162 | } |
| 160 | 163 | |
@@ -190,9 +193,12 @@ discard block |
||
| 190 | 193 | */ |
| 191 | 194 | public function request(): Request |
| 192 | 195 | { |
| 193 | - try { |
|
| 196 | + try |
|
| 197 | + { |
|
| 194 | 198 | $request = $this->container->get(Request::class); |
| 195 | - } catch (ContainerExceptionInterface $e) { |
|
| 199 | + } |
|
| 200 | + catch (ContainerExceptionInterface $e) |
|
| 201 | + { |
|
| 196 | 202 | $scope = implode('.', \array_reverse(Introspector::scopeNames($this->container))); |
| 197 | 203 | throw new ScopeException( |
| 198 | 204 | "Unable to get `ServerRequestInterface` in the `$scope` container scope", |
@@ -202,7 +208,8 @@ discard block |
||
| 202 | 208 | } |
| 203 | 209 | |
| 204 | 210 | // Flushing input state |
| 205 | - if ($this->request !== $request) { |
|
| 211 | + if ($this->request !== $request) |
|
| 212 | + { |
|
| 206 | 213 | $this->bags = []; |
| 207 | 214 | $this->request = $request; |
| 208 | 215 | } |
@@ -219,7 +226,8 @@ discard block |
||
| 219 | 226 | |
| 220 | 227 | $position = \strrpos($header, 'Bearer '); |
| 221 | 228 | |
| 222 | - if ($position !== false) { |
|
| 229 | + if ($position !== false) |
|
| 230 | + { |
|
| 223 | 231 | $header = \substr($header, $position + 7); |
| 224 | 232 | |
| 225 | 233 | return \str_contains($header, ',') |
@@ -273,16 +281,21 @@ discard block |
||
| 273 | 281 | public function isJsonExpected(bool $softMatch = false): bool |
| 274 | 282 | { |
| 275 | 283 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 276 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 277 | - if ($acceptHeader->has($jsonType)) { |
|
| 284 | + foreach ($this->jsonTypes as $jsonType) |
|
| 285 | + { |
|
| 286 | + if ($acceptHeader->has($jsonType)) |
|
| 287 | + { |
|
| 278 | 288 | return true; |
| 279 | 289 | } |
| 280 | 290 | } |
| 281 | 291 | |
| 282 | - if ($softMatch) { |
|
| 283 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 292 | + if ($softMatch) |
|
| 293 | + { |
|
| 294 | + foreach ($acceptHeader->getAll() as $item) |
|
| 295 | + { |
|
| 284 | 296 | $itemValue = \strtolower((string) $item->getValue()); |
| 285 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
| 297 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) |
|
| 298 | + { |
|
| 286 | 299 | return true; |
| 287 | 300 | } |
| 288 | 301 | } |
@@ -321,19 +334,22 @@ discard block |
||
| 321 | 334 | // ensure proper request association |
| 322 | 335 | $this->request(); |
| 323 | 336 | |
| 324 | - if (isset($this->bags[$name])) { |
|
| 337 | + if (isset($this->bags[$name])) |
|
| 338 | + { |
|
| 325 | 339 | return $this->bags[$name]; |
| 326 | 340 | } |
| 327 | 341 | |
| 328 | 342 | $definition = $this->findBagDefinition($name); |
| 329 | - if (!$definition) { |
|
| 343 | + if (!$definition) |
|
| 344 | + { |
|
| 330 | 345 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
| 331 | 346 | } |
| 332 | 347 | |
| 333 | 348 | $class = $definition['class']; |
| 334 | 349 | $data = \call_user_func([$this->request(), $definition['source']]); |
| 335 | 350 | |
| 336 | - if (!\is_array($data)) { |
|
| 351 | + if (!\is_array($data)) |
|
| 352 | + { |
|
| 337 | 353 | $data = (array)$data; |
| 338 | 354 | } |
| 339 | 355 | |
@@ -342,7 +358,8 @@ discard block |
||
| 342 | 358 | |
| 343 | 359 | public function hasBag(string $name): bool |
| 344 | 360 | { |
| 345 | - if (isset($this->bags[$name])) { |
|
| 361 | + if (isset($this->bags[$name])) |
|
| 362 | + { |
|
| 346 | 363 | return true; |
| 347 | 364 | } |
| 348 | 365 | |
@@ -362,12 +379,15 @@ discard block |
||
| 362 | 379 | */ |
| 363 | 380 | private function findBagDefinition(string $name): ?array |
| 364 | 381 | { |
| 365 | - if (isset($this->bagAssociations[$name])) { |
|
| 382 | + if (isset($this->bagAssociations[$name])) |
|
| 383 | + { |
|
| 366 | 384 | return $this->bagAssociations[$name]; |
| 367 | 385 | } |
| 368 | 386 | |
| 369 | - foreach ($this->bagAssociations as $bag) { |
|
| 370 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
| 387 | + foreach ($this->bagAssociations as $bag) |
|
| 388 | + { |
|
| 389 | + if (isset($bag['alias']) && $bag['alias'] === $name) |
|
| 390 | + { |
|
| 371 | 391 | return $bag; |
| 372 | 392 | } |
| 373 | 393 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | #[Proxy] private readonly ContainerInterface $container, |
| 47 | 47 | private readonly StemplerConfig $config, |
| 48 | 48 | private readonly ?StemplerCache $cache = null |
| 49 | - ) { |
|
| 49 | + ){ |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function getContainer(): ContainerInterface |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | public function getLoader(): LoaderInterface |
| 67 | 67 | { |
| 68 | - if ($this->loader === null) { |
|
| 68 | + if ($this->loader === null){ |
|
| 69 | 69 | throw new EngineException('No associated loader found'); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function getBuilder(ContextInterface $context): Builder |
| 79 | 79 | { |
| 80 | - if ($this->builder === null) { |
|
| 80 | + if ($this->builder === null){ |
|
| 81 | 81 | throw new EngineException('No associated builder found'); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // since view source support pre-processing we must ensure that context is always set |
| 85 | 85 | $loader = $this->builder->getLoader(); |
| 86 | - if ($loader instanceof StemplerLoader) { |
|
| 86 | + if ($loader instanceof StemplerLoader){ |
|
| 87 | 87 | $loader->setContext($context); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -101,20 +101,20 @@ discard block |
||
| 101 | 101 | // cache key |
| 102 | 102 | $key = $this->cacheKey($view, $context); |
| 103 | 103 | |
| 104 | - if ($this->cache !== null && $this->cache->isFresh($key)) { |
|
| 104 | + if ($this->cache !== null && $this->cache->isFresh($key)){ |
|
| 105 | 105 | $this->cache->load($key); |
| 106 | - } elseif (!\class_exists($class)) { |
|
| 107 | - try { |
|
| 106 | + } elseif (!\class_exists($class)){ |
|
| 107 | + try{ |
|
| 108 | 108 | $builder = $this->getBuilder($context); |
| 109 | 109 | |
| 110 | 110 | $result = $builder->compile($path); |
| 111 | - } catch (Throwable $e) { |
|
| 111 | + }catch (Throwable $e){ |
|
| 112 | 112 | throw new CompileException($e); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $compiled = $this->compileClass($class, $result); |
| 116 | 116 | |
| 117 | - if ($this->cache !== null) { |
|
| 117 | + if ($this->cache !== null){ |
|
| 118 | 118 | $this->cache->write( |
| 119 | 119 | $key, |
| 120 | 120 | $compiled, |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | $this->cache->load($key); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if (!\class_exists($class)) { |
|
| 130 | + if (!\class_exists($class)){ |
|
| 131 | 131 | // runtime initialization |
| 132 | - eval('?>' . $compiled); |
|
| 132 | + eval('?>'.$compiled); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if (!\class_exists($class) || !\is_subclass_of($class, ViewInterface::class)) { |
|
| 136 | + if (!\class_exists($class) || !\is_subclass_of($class, ViewInterface::class)){ |
|
| 137 | 137 | throw new EngineException(\sprintf('Unable to load `%s`, cache might be corrupted.', $path)); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | public function reset(string $path, ContextInterface $context): void |
| 144 | 144 | { |
| 145 | - if ($this->cache === null) { |
|
| 145 | + if ($this->cache === null){ |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function makeSourceMap(string $path, ContextInterface $context): ?SourceMap |
| 163 | 163 | { |
| 164 | - try { |
|
| 164 | + try{ |
|
| 165 | 165 | $builder = $this->getBuilder($context); |
| 166 | 166 | |
| 167 | 167 | // there is no need to cache sourcemaps since they are used during the exception only |
| 168 | 168 | return $builder->compile($path)->getSourceMap($builder->getLoader()); |
| 169 | - } catch (Throwable) { |
|
| 169 | + }catch (Throwable){ |
|
| 170 | 170 | return null; |
| 171 | 171 | } |
| 172 | 172 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | private function className(ViewSource $source, ContextInterface $context): string |
| 204 | 204 | { |
| 205 | - return $this->classPrefix . $this->cacheKey($source, $context); |
|
| 205 | + return $this->classPrefix.$this->cacheKey($source, $context); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | private function cacheKey(ViewSource $source, ContextInterface $context): string |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | $builder = new Builder($loader); |
| 223 | 223 | |
| 224 | 224 | $directivesGroup = new DirectiveGroup(); |
| 225 | - foreach ($this->getDirectives() as $directive) { |
|
| 225 | + foreach ($this->getDirectives() as $directive){ |
|
| 226 | 226 | $directivesGroup->addDirective($directive); |
| 227 | 227 | } |
| 228 | 228 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup($this->getDirectives()))); |
| 254 | 254 | |
| 255 | 255 | // ATS modifications |
| 256 | - foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor) { |
|
| 256 | + foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor){ |
|
| 257 | 257 | $builder->addVisitor($visitor, Builder::STAGE_PREPARE); |
| 258 | 258 | } |
| 259 | 259 | |
@@ -266,15 +266,15 @@ discard block |
||
| 266 | 266 | $builder->addVisitor(new ResolveImports($builder), Builder::STAGE_TRANSFORM); |
| 267 | 267 | $builder->addVisitor(new ExtendsParent($builder), Builder::STAGE_TRANSFORM); |
| 268 | 268 | |
| 269 | - foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor) { |
|
| 269 | + foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor){ |
|
| 270 | 270 | $builder->addVisitor($visitor, Builder::STAGE_TRANSFORM); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor) { |
|
| 273 | + foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor){ |
|
| 274 | 274 | $builder->addVisitor($visitor, Builder::STAGE_FINALIZE); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor) { |
|
| 277 | + foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor){ |
|
| 278 | 278 | $builder->addVisitor($visitor, Builder::STAGE_COMPILE); |
| 279 | 279 | } |
| 280 | 280 | |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | private function getVisitors(int $stage): iterable |
| 288 | 288 | { |
| 289 | 289 | $result = []; |
| 290 | - foreach ($this->config->getVisitors($stage) as $visitor) { |
|
| 291 | - if ($visitor instanceof Autowire) { |
|
| 290 | + foreach ($this->config->getVisitors($stage) as $visitor){ |
|
| 291 | + if ($visitor instanceof Autowire){ |
|
| 292 | 292 | $result[] = $visitor->resolve($this->container->get(FactoryInterface::class)); |
| 293 | 293 | continue; |
| 294 | 294 | } |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | private function getProcessors(): iterable |
| 306 | 306 | { |
| 307 | 307 | $result = []; |
| 308 | - foreach ($this->config->getProcessors() as $processor) { |
|
| 309 | - if ($processor instanceof Autowire) { |
|
| 308 | + foreach ($this->config->getProcessors() as $processor){ |
|
| 309 | + if ($processor instanceof Autowire){ |
|
| 310 | 310 | $result[] = $processor->resolve($this->container->get(FactoryInterface::class)); |
| 311 | 311 | continue; |
| 312 | 312 | } |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | private function getDirectives(): iterable |
| 324 | 324 | { |
| 325 | 325 | $result = []; |
| 326 | - foreach ($this->config->getDirectives() as $directive) { |
|
| 327 | - if ($directive instanceof Autowire) { |
|
| 326 | + foreach ($this->config->getDirectives() as $directive){ |
|
| 327 | + if ($directive instanceof Autowire){ |
|
| 328 | 328 | $result[] = $directive->resolve($this->container->get(FactoryInterface::class)); |
| 329 | 329 | continue; |
| 330 | 330 | } |
@@ -40,9 +40,9 @@ |
||
| 40 | 40 | public function defineDirectories(string $root): array |
| 41 | 41 | { |
| 42 | 42 | return [ |
| 43 | - 'app' => __DIR__ . '/fixtures', |
|
| 44 | - 'cache' => __DIR__ . '/cache', |
|
| 45 | - 'config' => __DIR__ . '/config', |
|
| 43 | + 'app' => __DIR__.'/fixtures', |
|
| 44 | + 'cache' => __DIR__.'/cache', |
|
| 45 | + 'config' => __DIR__.'/config', |
|
| 46 | 46 | ] + parent::defineDirectories($root); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -30,13 +30,13 @@ |
||
| 30 | 30 | #[TestScope("http")] |
| 31 | 31 | public function testCache(): void |
| 32 | 32 | { |
| 33 | - $this->assertCount(0, $this->files->getFiles(__DIR__ . '/cache/', '*.php')); |
|
| 33 | + $this->assertCount(0, $this->files->getFiles(__DIR__.'/cache/', '*.php')); |
|
| 34 | 34 | |
| 35 | 35 | $s = $this->getStempler(); |
| 36 | 36 | $this->assertSame('test', $s->get('test', new ViewContext())->render([])); |
| 37 | - $this->assertCount(2, $this->files->getFiles(__DIR__ . '/cache/', '*.php')); |
|
| 37 | + $this->assertCount(2, $this->files->getFiles(__DIR__.'/cache/', '*.php')); |
|
| 38 | 38 | |
| 39 | 39 | $s->reset('test', new ViewContext()); |
| 40 | - $this->assertCount(0, $this->files->getFiles(__DIR__ . '/../cache/', '*.php')); |
|
| 40 | + $this->assertCount(0, $this->files->getFiles(__DIR__.'/../cache/', '*.php')); |
|
| 41 | 41 | } |
| 42 | 42 | } |
@@ -33,14 +33,14 @@ |
||
| 33 | 33 | public function defineDirectories(string $root): array |
| 34 | 34 | { |
| 35 | 35 | return [ |
| 36 | - 'root' => __DIR__ . '/App', |
|
| 37 | - 'app' => __DIR__ . '/App' |
|
| 36 | + 'root' => __DIR__.'/App', |
|
| 37 | + 'app' => __DIR__.'/App' |
|
| 38 | 38 | ] + parent::defineDirectories($root); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function tearDown(): void |
| 42 | 42 | { |
| 43 | - foreach (glob(__DIR__ . '/App/runtime/cache/views/*.php') as $file) { |
|
| 43 | + foreach (glob(__DIR__.'/App/runtime/cache/views/*.php') as $file){ |
|
| 44 | 44 | @unlink($file); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | protected function getLogger(string $channel = null): LoggerInterface |
| 31 | 31 | { |
| 32 | - if ($channel !== null) { |
|
| 32 | + if ($channel !== null){ |
|
| 33 | 33 | return $this->allocateLogger($channel); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if ($this->logger !== null) { |
|
| 36 | + if ($this->logger !== null){ |
|
| 37 | 37 | return $this->logger; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | private function allocateLogger(string $channel): LoggerInterface |
| 48 | 48 | { |
| 49 | 49 | $container = ContainerScope::getContainer(); |
| 50 | - if ($container === null || !$container->has(LogsInterface::class)) { |
|
| 50 | + if ($container === null || !$container->has(LogsInterface::class)){ |
|
| 51 | 51 | return $this->logger ?? new NullLogger(); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -29,11 +29,13 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | protected function getLogger(string $channel = null): LoggerInterface |
| 31 | 31 | { |
| 32 | - if ($channel !== null) { |
|
| 32 | + if ($channel !== null) |
|
| 33 | + { |
|
| 33 | 34 | return $this->allocateLogger($channel); |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | - if ($this->logger !== null) { |
|
| 37 | + if ($this->logger !== null) |
|
| 38 | + { |
|
| 37 | 39 | return $this->logger; |
| 38 | 40 | } |
| 39 | 41 | |
@@ -47,7 +49,8 @@ discard block |
||
| 47 | 49 | private function allocateLogger(string $channel): LoggerInterface |
| 48 | 50 | { |
| 49 | 51 | $container = ContainerScope::getContainer(); |
| 50 | - if ($container === null || !$container->has(LogsInterface::class)) { |
|
| 52 | + if ($container === null || !$container->has(LogsInterface::class)) |
|
| 53 | + { |
|
| 51 | 54 | return $this->logger ?? new NullLogger(); |
| 52 | 55 | } |
| 53 | 56 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function testNoScope(): void |
| 36 | 36 | { |
| 37 | 37 | $c = new Container(); |
| 38 | - $c->runScope(new Scope(), function () { |
|
| 38 | + $c->runScope(new Scope(), function (){ |
|
| 39 | 39 | $logger = $this->getLogger(); |
| 40 | 40 | $this->assertInstanceOf(NullLogger::class, $this->getLogger()); |
| 41 | 41 | $this->assertSame($logger, $this->getLogger()); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | $c->bind(LogsInterface::class, $mock); |
| 53 | 53 | |
| 54 | - $c->runScope(new Scope(), function () { |
|
| 54 | + $c->runScope(new Scope(), function (){ |
|
| 55 | 55 | $logger = $this->getLogger(); |
| 56 | 56 | $this->assertInstanceOf(\Spiral\Logger\NullLogger::class, $this->getLogger()); |
| 57 | 57 | $this->assertSame($logger, $this->getLogger()); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $this->container->bind( |
| 74 | 74 | ConfiguratorInterface::class, |
| 75 | 75 | new ConfigManager( |
| 76 | - new class() implements LoaderInterface { |
|
| 76 | + new class() implements LoaderInterface{ |
|
| 77 | 77 | public function has(string $section): bool |
| 78 | 78 | { |
| 79 | 79 | return false; |
@@ -35,7 +35,8 @@ discard block |
||
| 35 | 35 | public function testNoScope(): void |
| 36 | 36 | { |
| 37 | 37 | $c = new Container(); |
| 38 | - $c->runScope(new Scope(), function () { |
|
| 38 | + $c->runScope(new Scope(), function () |
|
| 39 | + { |
|
| 39 | 40 | $logger = $this->getLogger(); |
| 40 | 41 | $this->assertInstanceOf(NullLogger::class, $this->getLogger()); |
| 41 | 42 | $this->assertSame($logger, $this->getLogger()); |
@@ -51,7 +52,8 @@ discard block |
||
| 51 | 52 | |
| 52 | 53 | $c->bind(LogsInterface::class, $mock); |
| 53 | 54 | |
| 54 | - $c->runScope(new Scope(), function () { |
|
| 55 | + $c->runScope(new Scope(), function () |
|
| 56 | + { |
|
| 55 | 57 | $logger = $this->getLogger(); |
| 56 | 58 | $this->assertInstanceOf(\Spiral\Logger\NullLogger::class, $this->getLogger()); |
| 57 | 59 | $this->assertSame($logger, $this->getLogger()); |
@@ -73,7 +75,8 @@ discard block |
||
| 73 | 75 | $this->container->bind( |
| 74 | 76 | ConfiguratorInterface::class, |
| 75 | 77 | new ConfigManager( |
| 76 | - new class() implements LoaderInterface { |
|
| 78 | + new class() implements LoaderInterface |
|
| 79 | + { |
|
| 77 | 80 | public function has(string $section): bool |
| 78 | 81 | { |
| 79 | 82 | return false; |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $s = $this->getStempler(); |
| 54 | 54 | |
| 55 | - try { |
|
| 55 | + try{ |
|
| 56 | 56 | $s->get('echo', new ViewContext())->render(); |
| 57 | 57 | $this->fail('Exception expected'); |
| 58 | - } catch (RenderException $e) { |
|
| 58 | + }catch (RenderException $e){ |
|
| 59 | 59 | $t = $e->getUserTrace()[0]; |
| 60 | 60 | |
| 61 | 61 | $this->assertSame(2, $t['line']); |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | $s = $this->getStempler(); |
| 69 | 69 | |
| 70 | - try { |
|
| 70 | + try{ |
|
| 71 | 71 | $s->get('other:echo-in', new ViewContext())->render(); |
| 72 | 72 | $this->fail('Exception expected'); |
| 73 | - } catch (RenderException $e) { |
|
| 73 | + }catch (RenderException $e){ |
|
| 74 | 74 | $t = $e->getUserTrace(); |
| 75 | 75 | $this->assertCount(2, $t); |
| 76 | 76 | |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | $twig = $this->getStempler(); |
| 88 | 88 | |
| 89 | - try { |
|
| 89 | + try{ |
|
| 90 | 90 | $twig->get('other:bad', new ViewContext()); |
| 91 | - } catch (CompileException $e) { |
|
| 91 | + }catch (CompileException $e){ |
|
| 92 | 92 | $this->assertStringContainsString('bad.dark.php', $e->getFile()); |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -52,10 +52,13 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $s = $this->getStempler(); |
| 54 | 54 | |
| 55 | - try { |
|
| 55 | + try |
|
| 56 | + { |
|
| 56 | 57 | $s->get('echo', new ViewContext())->render(); |
| 57 | 58 | $this->fail('Exception expected'); |
| 58 | - } catch (RenderException $e) { |
|
| 59 | + } |
|
| 60 | + catch (RenderException $e) |
|
| 61 | + { |
|
| 59 | 62 | $t = $e->getUserTrace()[0]; |
| 60 | 63 | |
| 61 | 64 | $this->assertSame(2, $t['line']); |
@@ -67,10 +70,13 @@ discard block |
||
| 67 | 70 | { |
| 68 | 71 | $s = $this->getStempler(); |
| 69 | 72 | |
| 70 | - try { |
|
| 73 | + try |
|
| 74 | + { |
|
| 71 | 75 | $s->get('other:echo-in', new ViewContext())->render(); |
| 72 | 76 | $this->fail('Exception expected'); |
| 73 | - } catch (RenderException $e) { |
|
| 77 | + } |
|
| 78 | + catch (RenderException $e) |
|
| 79 | + { |
|
| 74 | 80 | $t = $e->getUserTrace(); |
| 75 | 81 | $this->assertCount(2, $t); |
| 76 | 82 | |
@@ -86,9 +92,12 @@ discard block |
||
| 86 | 92 | { |
| 87 | 93 | $twig = $this->getStempler(); |
| 88 | 94 | |
| 89 | - try { |
|
| 95 | + try |
|
| 96 | + { |
|
| 90 | 97 | $twig->get('other:bad', new ViewContext()); |
| 91 | - } catch (CompileException $e) { |
|
| 98 | + } |
|
| 99 | + catch (CompileException $e) |
|
| 100 | + { |
|
| 92 | 101 | $this->assertStringContainsString('bad.dark.php', $e->getFile()); |
| 93 | 102 | } |
| 94 | 103 | } |