@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | public function __construct( |
| 24 | 24 | private readonly LoaderInterface $loader, |
| 25 | 25 | array $processors |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | $this->processors = $processors; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function load(string $path): Source |
| 42 | 42 | { |
| 43 | - if (!$this->context instanceof \Spiral\Views\ContextInterface) { |
|
| 43 | + if (!$this->context instanceof \Spiral\Views\ContextInterface){ |
|
| 44 | 44 | throw new EngineException('Unable to use StemplerLoader without given context.'); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -40,7 +40,8 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | public function load(string $path): Source |
| 42 | 42 | { |
| 43 | - if (!$this->context instanceof \Spiral\Views\ContextInterface) { |
|
| 43 | + if (!$this->context instanceof \Spiral\Views\ContextInterface) |
|
| 44 | + { |
|
| 44 | 45 | throw new EngineException('Unable to use StemplerLoader without given context.'); |
| 45 | 46 | } |
| 46 | 47 | |
@@ -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 instanceof \Spiral\Views\LoaderInterface) { |
|
| 68 | + if (!$this->loader instanceof \Spiral\Views\LoaderInterface){ |
|
| 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 instanceof \Spiral\Stempler\Builder) { |
|
| 80 | + if (!$this->builder instanceof \Spiral\Stempler\Builder){ |
|
| 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 instanceof \Spiral\Stempler\StemplerCache && $this->cache->isFresh($key)) { |
|
| 104 | + if ($this->cache instanceof \Spiral\Stempler\StemplerCache && $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 instanceof \Spiral\Stempler\StemplerCache) { |
|
| 117 | + if ($this->cache instanceof \Spiral\Stempler\StemplerCache){ |
|
| 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 instanceof \Spiral\Stempler\StemplerCache) { |
|
| 145 | + if (!$this->cache instanceof \Spiral\Stempler\StemplerCache){ |
|
| 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 | } |
@@ -65,7 +65,8 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | public function getLoader(): LoaderInterface |
| 67 | 67 | { |
| 68 | - if (!$this->loader instanceof \Spiral\Views\LoaderInterface) { |
|
| 68 | + if (!$this->loader instanceof \Spiral\Views\LoaderInterface) |
|
| 69 | + { |
|
| 69 | 70 | throw new EngineException('No associated loader found'); |
| 70 | 71 | } |
| 71 | 72 | |
@@ -77,13 +78,15 @@ discard block |
||
| 77 | 78 | */ |
| 78 | 79 | public function getBuilder(ContextInterface $context): Builder |
| 79 | 80 | { |
| 80 | - if (!$this->builder instanceof \Spiral\Stempler\Builder) { |
|
| 81 | + if (!$this->builder instanceof \Spiral\Stempler\Builder) |
|
| 82 | + { |
|
| 81 | 83 | throw new EngineException('No associated builder found'); |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | // since view source support pre-processing we must ensure that context is always set |
| 85 | 87 | $loader = $this->builder->getLoader(); |
| 86 | - if ($loader instanceof StemplerLoader) { |
|
| 88 | + if ($loader instanceof StemplerLoader) |
|
| 89 | + { |
|
| 87 | 90 | $loader->setContext($context); |
| 88 | 91 | } |
| 89 | 92 | |
@@ -101,20 +104,27 @@ discard block |
||
| 101 | 104 | // cache key |
| 102 | 105 | $key = $this->cacheKey($view, $context); |
| 103 | 106 | |
| 104 | - if ($this->cache instanceof \Spiral\Stempler\StemplerCache && $this->cache->isFresh($key)) { |
|
| 107 | + if ($this->cache instanceof \Spiral\Stempler\StemplerCache && $this->cache->isFresh($key)) |
|
| 108 | + { |
|
| 105 | 109 | $this->cache->load($key); |
| 106 | - } elseif (!\class_exists($class)) { |
|
| 107 | - try { |
|
| 110 | + } |
|
| 111 | + elseif (!\class_exists($class)) |
|
| 112 | + { |
|
| 113 | + try |
|
| 114 | + { |
|
| 108 | 115 | $builder = $this->getBuilder($context); |
| 109 | 116 | |
| 110 | 117 | $result = $builder->compile($path); |
| 111 | - } catch (Throwable $e) { |
|
| 118 | + } |
|
| 119 | + catch (Throwable $e) |
|
| 120 | + { |
|
| 112 | 121 | throw new CompileException($e); |
| 113 | 122 | } |
| 114 | 123 | |
| 115 | 124 | $compiled = $this->compileClass($class, $result); |
| 116 | 125 | |
| 117 | - if ($this->cache instanceof \Spiral\Stempler\StemplerCache) { |
|
| 126 | + if ($this->cache instanceof \Spiral\Stempler\StemplerCache) |
|
| 127 | + { |
|
| 118 | 128 | $this->cache->write( |
| 119 | 129 | $key, |
| 120 | 130 | $compiled, |
@@ -127,13 +137,15 @@ discard block |
||
| 127 | 137 | $this->cache->load($key); |
| 128 | 138 | } |
| 129 | 139 | |
| 130 | - if (!\class_exists($class)) { |
|
| 140 | + if (!\class_exists($class)) |
|
| 141 | + { |
|
| 131 | 142 | // runtime initialization |
| 132 | 143 | eval('?>' . $compiled); |
| 133 | 144 | } |
| 134 | 145 | } |
| 135 | 146 | |
| 136 | - if (!\class_exists($class) || !\is_subclass_of($class, ViewInterface::class)) { |
|
| 147 | + if (!\class_exists($class) || !\is_subclass_of($class, ViewInterface::class)) |
|
| 148 | + { |
|
| 137 | 149 | throw new EngineException(\sprintf('Unable to load `%s`, cache might be corrupted.', $path)); |
| 138 | 150 | } |
| 139 | 151 | |
@@ -142,7 +154,8 @@ discard block |
||
| 142 | 154 | |
| 143 | 155 | public function reset(string $path, ContextInterface $context): void |
| 144 | 156 | { |
| 145 | - if (!$this->cache instanceof \Spiral\Stempler\StemplerCache) { |
|
| 157 | + if (!$this->cache instanceof \Spiral\Stempler\StemplerCache) |
|
| 158 | + { |
|
| 146 | 159 | return; |
| 147 | 160 | } |
| 148 | 161 | |
@@ -161,12 +174,15 @@ discard block |
||
| 161 | 174 | */ |
| 162 | 175 | public function makeSourceMap(string $path, ContextInterface $context): ?SourceMap |
| 163 | 176 | { |
| 164 | - try { |
|
| 177 | + try |
|
| 178 | + { |
|
| 165 | 179 | $builder = $this->getBuilder($context); |
| 166 | 180 | |
| 167 | 181 | // there is no need to cache sourcemaps since they are used during the exception only |
| 168 | 182 | return $builder->compile($path)->getSourceMap($builder->getLoader()); |
| 169 | - } catch (Throwable) { |
|
| 183 | + } |
|
| 184 | + catch (Throwable) |
|
| 185 | + { |
|
| 170 | 186 | return null; |
| 171 | 187 | } |
| 172 | 188 | } |
@@ -222,7 +238,8 @@ discard block |
||
| 222 | 238 | $builder = new Builder($loader); |
| 223 | 239 | |
| 224 | 240 | $directivesGroup = new DirectiveGroup(); |
| 225 | - foreach ($this->getDirectives() as $directive) { |
|
| 241 | + foreach ($this->getDirectives() as $directive) |
|
| 242 | + { |
|
| 226 | 243 | $directivesGroup->addDirective($directive); |
| 227 | 244 | } |
| 228 | 245 | |
@@ -253,7 +270,8 @@ discard block |
||
| 253 | 270 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup($this->getDirectives()))); |
| 254 | 271 | |
| 255 | 272 | // ATS modifications |
| 256 | - foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor) { |
|
| 273 | + foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor) |
|
| 274 | + { |
|
| 257 | 275 | $builder->addVisitor($visitor, Builder::STAGE_PREPARE); |
| 258 | 276 | } |
| 259 | 277 | |
@@ -266,15 +284,18 @@ discard block |
||
| 266 | 284 | $builder->addVisitor(new ResolveImports($builder), Builder::STAGE_TRANSFORM); |
| 267 | 285 | $builder->addVisitor(new ExtendsParent($builder), Builder::STAGE_TRANSFORM); |
| 268 | 286 | |
| 269 | - foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor) { |
|
| 287 | + foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor) |
|
| 288 | + { |
|
| 270 | 289 | $builder->addVisitor($visitor, Builder::STAGE_TRANSFORM); |
| 271 | 290 | } |
| 272 | 291 | |
| 273 | - foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor) { |
|
| 292 | + foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor) |
|
| 293 | + { |
|
| 274 | 294 | $builder->addVisitor($visitor, Builder::STAGE_FINALIZE); |
| 275 | 295 | } |
| 276 | 296 | |
| 277 | - foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor) { |
|
| 297 | + foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor) |
|
| 298 | + { |
|
| 278 | 299 | $builder->addVisitor($visitor, Builder::STAGE_COMPILE); |
| 279 | 300 | } |
| 280 | 301 | |
@@ -287,8 +308,10 @@ discard block |
||
| 287 | 308 | private function getVisitors(int $stage): iterable |
| 288 | 309 | { |
| 289 | 310 | $result = []; |
| 290 | - foreach ($this->config->getVisitors($stage) as $visitor) { |
|
| 291 | - if ($visitor instanceof Autowire) { |
|
| 311 | + foreach ($this->config->getVisitors($stage) as $visitor) |
|
| 312 | + { |
|
| 313 | + if ($visitor instanceof Autowire) |
|
| 314 | + { |
|
| 292 | 315 | $result[] = $visitor->resolve($this->container->get(FactoryInterface::class)); |
| 293 | 316 | continue; |
| 294 | 317 | } |
@@ -305,8 +328,10 @@ discard block |
||
| 305 | 328 | private function getProcessors(): iterable |
| 306 | 329 | { |
| 307 | 330 | $result = []; |
| 308 | - foreach ($this->config->getProcessors() as $processor) { |
|
| 309 | - if ($processor instanceof Autowire) { |
|
| 331 | + foreach ($this->config->getProcessors() as $processor) |
|
| 332 | + { |
|
| 333 | + if ($processor instanceof Autowire) |
|
| 334 | + { |
|
| 310 | 335 | $result[] = $processor->resolve($this->container->get(FactoryInterface::class)); |
| 311 | 336 | continue; |
| 312 | 337 | } |
@@ -323,8 +348,10 @@ discard block |
||
| 323 | 348 | private function getDirectives(): iterable |
| 324 | 349 | { |
| 325 | 350 | $result = []; |
| 326 | - foreach ($this->config->getDirectives() as $directive) { |
|
| 327 | - if ($directive instanceof Autowire) { |
|
| 351 | + foreach ($this->config->getDirectives() as $directive) |
|
| 352 | + { |
|
| 353 | + if ($directive instanceof Autowire) |
|
| 354 | + { |
|
| 328 | 355 | $result[] = $directive->resolve($this->container->get(FactoryInterface::class)); |
| 329 | 356 | continue; |
| 330 | 357 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | protected StemplerEngine $engine, |
| 21 | 21 | protected ViewSource $view, |
| 22 | 22 | protected ContextInterface $context |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | $this->container = $engine->getContainer(); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $this->context |
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | - if (!$sourcemap instanceof \Spiral\Stempler\Compiler\SourceMap) { |
|
| 37 | + if (!$sourcemap instanceof \Spiral\Stempler\Compiler\SourceMap){ |
|
| 38 | 38 | return $e; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -34,7 +34,8 @@ |
||
| 34 | 34 | $this->context |
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | - if (!$sourcemap instanceof \Spiral\Stempler\Compiler\SourceMap) { |
|
| 37 | + if (!$sourcemap instanceof \Spiral\Stempler\Compiler\SourceMap) |
|
| 38 | + { |
|
| 38 | 39 | return $e; |
| 39 | 40 | } |
| 40 | 41 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | private readonly MonologConfig $config, |
| 32 | 32 | ListenerRegistryInterface $listenerRegistry, |
| 33 | 33 | private readonly FactoryInterface $factory |
| 34 | - ) { |
|
| 34 | + ){ |
|
| 35 | 35 | $this->eventHandler = new EventHandler($listenerRegistry, $config->getEventLevel()); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $default = $this->config->getDefault(); |
| 41 | 41 | |
| 42 | - if ($channel === null || $channel === $default) { |
|
| 43 | - if ($this->default instanceof \Psr\Log\LoggerInterface) { |
|
| 42 | + if ($channel === null || $channel === $default){ |
|
| 43 | + if ($this->default instanceof \Psr\Log\LoggerInterface){ |
|
| 44 | 44 | // we should use only one default logger per system |
| 45 | 45 | return $this->default; |
| 46 | 46 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | public function reset(): void |
| 71 | 71 | { |
| 72 | - if ($this->default instanceof ResettableInterface) { |
|
| 72 | + if ($this->default instanceof ResettableInterface){ |
|
| 73 | 73 | $this->default->reset(); |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | // always include default handler |
| 86 | 86 | $handlers = []; |
| 87 | 87 | |
| 88 | - foreach ($this->config->getHandlers($channel) as $handler) { |
|
| 89 | - if (!$handler instanceof Autowire) { |
|
| 88 | + foreach ($this->config->getHandlers($channel) as $handler){ |
|
| 89 | + if (!$handler instanceof Autowire){ |
|
| 90 | 90 | $handlers[] = $handler; |
| 91 | 91 | continue; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - try { |
|
| 94 | + try{ |
|
| 95 | 95 | $handlers[] = $handler->resolve($this->factory); |
| 96 | - } catch (ContainerExceptionInterface $e) { |
|
| 96 | + }catch (ContainerExceptionInterface $e){ |
|
| 97 | 97 | throw new ConfigException($e->getMessage(), $e->getCode(), $e); |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -111,20 +111,20 @@ discard block |
||
| 111 | 111 | protected function getProcessors(string $channel): array |
| 112 | 112 | { |
| 113 | 113 | $processors = []; |
| 114 | - foreach ($this->config->getProcessors($channel) as $processor) { |
|
| 115 | - if (!$processor instanceof Autowire) { |
|
| 114 | + foreach ($this->config->getProcessors($channel) as $processor){ |
|
| 115 | + if (!$processor instanceof Autowire){ |
|
| 116 | 116 | $processors[] = $processor; |
| 117 | 117 | continue; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - try { |
|
| 120 | + try{ |
|
| 121 | 121 | $processors[] = $processor->resolve($this->factory); |
| 122 | - } catch (ContainerExceptionInterface $e) { |
|
| 122 | + }catch (ContainerExceptionInterface $e){ |
|
| 123 | 123 | throw new ConfigException($e->getMessage(), $e->getCode(), $e); |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if ($processors === []) { |
|
| 127 | + if ($processors === []){ |
|
| 128 | 128 | $processors[] = new PsrLogMessageProcessor(); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -39,8 +39,10 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $default = $this->config->getDefault(); |
| 41 | 41 | |
| 42 | - if ($channel === null || $channel === $default) { |
|
| 43 | - if ($this->default instanceof \Psr\Log\LoggerInterface) { |
|
| 42 | + if ($channel === null || $channel === $default) |
|
| 43 | + { |
|
| 44 | + if ($this->default instanceof \Psr\Log\LoggerInterface) |
|
| 45 | + { |
|
| 44 | 46 | // we should use only one default logger per system |
| 45 | 47 | return $this->default; |
| 46 | 48 | } |
@@ -69,7 +71,8 @@ discard block |
||
| 69 | 71 | |
| 70 | 72 | public function reset(): void |
| 71 | 73 | { |
| 72 | - if ($this->default instanceof ResettableInterface) { |
|
| 74 | + if ($this->default instanceof ResettableInterface) |
|
| 75 | + { |
|
| 73 | 76 | $this->default->reset(); |
| 74 | 77 | } |
| 75 | 78 | } |
@@ -85,15 +88,20 @@ discard block |
||
| 85 | 88 | // always include default handler |
| 86 | 89 | $handlers = []; |
| 87 | 90 | |
| 88 | - foreach ($this->config->getHandlers($channel) as $handler) { |
|
| 89 | - if (!$handler instanceof Autowire) { |
|
| 91 | + foreach ($this->config->getHandlers($channel) as $handler) |
|
| 92 | + { |
|
| 93 | + if (!$handler instanceof Autowire) |
|
| 94 | + { |
|
| 90 | 95 | $handlers[] = $handler; |
| 91 | 96 | continue; |
| 92 | 97 | } |
| 93 | 98 | |
| 94 | - try { |
|
| 99 | + try |
|
| 100 | + { |
|
| 95 | 101 | $handlers[] = $handler->resolve($this->factory); |
| 96 | - } catch (ContainerExceptionInterface $e) { |
|
| 102 | + } |
|
| 103 | + catch (ContainerExceptionInterface $e) |
|
| 104 | + { |
|
| 97 | 105 | throw new ConfigException($e->getMessage(), $e->getCode(), $e); |
| 98 | 106 | } |
| 99 | 107 | } |
@@ -111,20 +119,26 @@ discard block |
||
| 111 | 119 | protected function getProcessors(string $channel): array |
| 112 | 120 | { |
| 113 | 121 | $processors = []; |
| 114 | - foreach ($this->config->getProcessors($channel) as $processor) { |
|
| 115 | - if (!$processor instanceof Autowire) { |
|
| 122 | + foreach ($this->config->getProcessors($channel) as $processor) |
|
| 123 | + { |
|
| 124 | + if (!$processor instanceof Autowire) |
|
| 125 | + { |
|
| 116 | 126 | $processors[] = $processor; |
| 117 | 127 | continue; |
| 118 | 128 | } |
| 119 | 129 | |
| 120 | - try { |
|
| 130 | + try |
|
| 131 | + { |
|
| 121 | 132 | $processors[] = $processor->resolve($this->factory); |
| 122 | - } catch (ContainerExceptionInterface $e) { |
|
| 133 | + } |
|
| 134 | + catch (ContainerExceptionInterface $e) |
|
| 135 | + { |
|
| 123 | 136 | throw new ConfigException($e->getMessage(), $e->getCode(), $e); |
| 124 | 137 | } |
| 125 | 138 | } |
| 126 | 139 | |
| 127 | - if ($processors === []) { |
|
| 140 | + if ($processors === []) |
|
| 141 | + { |
|
| 128 | 142 | $processors[] = new PsrLogMessageProcessor(); |
| 129 | 143 | } |
| 130 | 144 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $target = Target::fromReflectionMethod($reflection, self::class); |
| 48 | 48 | |
| 49 | 49 | self::assertSame($reflection, $target->getReflection()); |
| 50 | - self::assertSame(self::class . '->' . __FUNCTION__, (string)$target); |
|
| 50 | + self::assertSame(self::class.'->'.__FUNCTION__, (string)$target); |
|
| 51 | 51 | self::assertNull($target->getObject()); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $target = Target::fromReflectionMethod($reflection, $this); |
| 59 | 59 | |
| 60 | 60 | self::assertSame($reflection, $target->getReflection()); |
| 61 | - self::assertSame(self::class . '->' . __FUNCTION__, (string)$target); |
|
| 61 | + self::assertSame(self::class.'->'.__FUNCTION__, (string)$target); |
|
| 62 | 62 | self::assertNotNull($target->getObject()); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $reflection = $target->getReflection(); |
| 125 | 125 | self::assertSame($hasReflection, $reflection instanceof \ReflectionFunctionAbstract); |
| 126 | 126 | self::assertNull($target->getObject()); |
| 127 | - if ($hasReflection) { |
|
| 127 | + if ($hasReflection){ |
|
| 128 | 128 | self::assertInstanceOf(\ReflectionMethod::class, $reflection); |
| 129 | 129 | self::assertSame($action, $reflection->getName()); |
| 130 | 130 | } |
@@ -124,7 +124,8 @@ |
||
| 124 | 124 | $reflection = $target->getReflection(); |
| 125 | 125 | self::assertSame($hasReflection, $reflection instanceof \ReflectionFunctionAbstract); |
| 126 | 126 | self::assertNull($target->getObject()); |
| 127 | - if ($hasReflection) { |
|
| 127 | + if ($hasReflection) |
|
| 128 | + { |
|
| 128 | 129 | self::assertInstanceOf(\ReflectionMethod::class, $reflection); |
| 129 | 130 | self::assertSame($action, $reflection->getName()); |
| 130 | 131 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function __construct( |
| 29 | 29 | private readonly ?EventDispatcherInterface $dispatcher = null |
| 30 | - ) { |
|
| 30 | + ){ |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | public function withInterceptors(InterceptorInterface ...$interceptors): self |
| 37 | 37 | { |
| 38 | 38 | $clone = clone $this; |
| 39 | - foreach ($interceptors as $interceptor) { |
|
| 39 | + foreach ($interceptors as $interceptor){ |
|
| 40 | 40 | $clone->interceptors[] = $interceptor; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function handle(CallContextInterface $context): mixed |
| 57 | 57 | { |
| 58 | - if (!$this->handler instanceof \Spiral\Interceptors\HandlerInterface) { |
|
| 58 | + if (!$this->handler instanceof \Spiral\Interceptors\HandlerInterface){ |
|
| 59 | 59 | throw new InterceptorException('Unable to invoke pipeline without last handler.'); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if (isset($this->interceptors[$this->position])) { |
|
| 62 | + if (isset($this->interceptors[$this->position])){ |
|
| 63 | 63 | $interceptor = $this->interceptors[$this->position]; |
| 64 | 64 | |
| 65 | 65 | $this->dispatcher?->dispatch(new InterceptorCalling(context: $context, interceptor: $interceptor)); |
@@ -36,7 +36,8 @@ discard block |
||
| 36 | 36 | public function withInterceptors(InterceptorInterface ...$interceptors): self |
| 37 | 37 | { |
| 38 | 38 | $clone = clone $this; |
| 39 | - foreach ($interceptors as $interceptor) { |
|
| 39 | + foreach ($interceptors as $interceptor) |
|
| 40 | + { |
|
| 40 | 41 | $clone->interceptors[] = $interceptor; |
| 41 | 42 | } |
| 42 | 43 | |
@@ -55,11 +56,13 @@ discard block |
||
| 55 | 56 | */ |
| 56 | 57 | public function handle(CallContextInterface $context): mixed |
| 57 | 58 | { |
| 58 | - if (!$this->handler instanceof \Spiral\Interceptors\HandlerInterface) { |
|
| 59 | + if (!$this->handler instanceof \Spiral\Interceptors\HandlerInterface) |
|
| 60 | + { |
|
| 59 | 61 | throw new InterceptorException('Unable to invoke pipeline without last handler.'); |
| 60 | 62 | } |
| 61 | 63 | |
| 62 | - if (isset($this->interceptors[$this->position])) { |
|
| 64 | + if (isset($this->interceptors[$this->position])) |
|
| 65 | + { |
|
| 63 | 66 | $interceptor = $this->interceptors[$this->position]; |
| 64 | 67 | |
| 65 | 68 | $this->dispatcher?->dispatch(new InterceptorCalling(context: $context, interceptor: $interceptor)); |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | private readonly PermissionsInterface $permissions, |
| 19 | 19 | private ?ActorInterface $actor = null, |
| 20 | 20 | private array $roles = [] |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function allows(string $permission, array $context = []): bool |
| 25 | 25 | { |
| 26 | 26 | $allows = false; |
| 27 | - foreach ($this->getRoles() as $role) { |
|
| 28 | - if (!$this->permissions->hasRole($role)) { |
|
| 27 | + foreach ($this->getRoles() as $role){ |
|
| 28 | + if (!$this->permissions->hasRole($role)){ |
|
| 29 | 29 | continue; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function getActor(): ActorInterface |
| 66 | 66 | { |
| 67 | - if (!$this->actor instanceof \Spiral\Security\ActorInterface) { |
|
| 67 | + if (!$this->actor instanceof \Spiral\Security\ActorInterface){ |
|
| 68 | 68 | throw new GuardException('Unable to get Guard Actor, no value set'); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -24,8 +24,10 @@ discard block |
||
| 24 | 24 | public function allows(string $permission, array $context = []): bool |
| 25 | 25 | { |
| 26 | 26 | $allows = false; |
| 27 | - foreach ($this->getRoles() as $role) { |
|
| 28 | - if (!$this->permissions->hasRole($role)) { |
|
| 27 | + foreach ($this->getRoles() as $role) |
|
| 28 | + { |
|
| 29 | + if (!$this->permissions->hasRole($role)) |
|
| 30 | + { |
|
| 29 | 31 | continue; |
| 30 | 32 | } |
| 31 | 33 | |
@@ -64,7 +66,8 @@ discard block |
||
| 64 | 66 | */ |
| 65 | 67 | public function getActor(): ActorInterface |
| 66 | 68 | { |
| 67 | - if (!$this->actor instanceof \Spiral\Security\ActorInterface) { |
|
| 69 | + if (!$this->actor instanceof \Spiral\Security\ActorInterface) |
|
| 70 | + { |
|
| 68 | 71 | throw new GuardException('Unable to get Guard Actor, no value set'); |
| 69 | 72 | } |
| 70 | 73 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public function getGuard(): GuardInterface |
| 21 | 21 | { |
| 22 | 22 | $container = ContainerScope::getContainer(); |
| 23 | - if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(GuardInterface::class)) { |
|
| 23 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(GuardInterface::class)){ |
|
| 24 | 24 | throw new ScopeException( |
| 25 | 25 | 'Unable to get `GuardInterface`, binding is missing or container scope is not set' |
| 26 | 26 | ); |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | protected function resolvePermission(string $permission): string |
| 46 | 46 | { |
| 47 | - if (\defined('static::GUARD_NAMESPACE')) { |
|
| 47 | + if (\defined('static::GUARD_NAMESPACE')){ |
|
| 48 | 48 | // Yay! Isolation |
| 49 | - $permission = \constant(static::class . '::' . 'GUARD_NAMESPACE') . '.' . $permission; |
|
| 49 | + $permission = \constant(static::class.'::'.'GUARD_NAMESPACE').'.'.$permission; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | return $permission; |
@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | public function getGuard(): GuardInterface |
| 21 | 21 | { |
| 22 | 22 | $container = ContainerScope::getContainer(); |
| 23 | - if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(GuardInterface::class)) { |
|
| 23 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(GuardInterface::class)) |
|
| 24 | + { |
|
| 24 | 25 | throw new ScopeException( |
| 25 | 26 | 'Unable to get `GuardInterface`, binding is missing or container scope is not set' |
| 26 | 27 | ); |
@@ -44,7 +45,8 @@ discard block |
||
| 44 | 45 | */ |
| 45 | 46 | protected function resolvePermission(string $permission): string |
| 46 | 47 | { |
| 47 | - if (\defined('static::GUARD_NAMESPACE')) { |
|
| 48 | + if (\defined('static::GUARD_NAMESPACE')) |
|
| 49 | + { |
|
| 48 | 50 | // Yay! Isolation |
| 49 | 51 | $permission = \constant(static::class . '::' . 'GUARD_NAMESPACE') . '.' . $permission; |
| 50 | 52 | } |
@@ -24,29 +24,29 @@ discard block |
||
| 24 | 24 | private readonly ReaderInterface $reader, |
| 25 | 25 | private readonly ListenerFactoryInterface $factory, |
| 26 | 26 | private readonly ?ListenerRegistryInterface $registry = null, |
| 27 | - ) { |
|
| 27 | + ){ |
|
| 28 | 28 | // Look for Spiral\Events\Attribute\Listener attribute only when ListenerRegistry provided by container |
| 29 | - if ($this->registry instanceof \Spiral\Events\ListenerRegistryInterface) { |
|
| 29 | + if ($this->registry instanceof \Spiral\Events\ListenerRegistryInterface){ |
|
| 30 | 30 | $listenerRegistry->addListener($this); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function process(): void |
| 35 | 35 | { |
| 36 | - if (!$this->registry instanceof \Spiral\Events\ListenerRegistryInterface) { |
|
| 36 | + if (!$this->registry instanceof \Spiral\Events\ListenerRegistryInterface){ |
|
| 37 | 37 | return; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if (!$this->collected) { |
|
| 40 | + if (!$this->collected){ |
|
| 41 | 41 | throw new \RuntimeException(\sprintf('Tokenizer did not finalize %s listener.', self::class)); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - foreach ($this->attributes as $listener => $attributes) { |
|
| 45 | - foreach ($attributes as $attribute) { |
|
| 44 | + foreach ($this->attributes as $listener => $attributes){ |
|
| 45 | + foreach ($attributes as $attribute){ |
|
| 46 | 46 | $method = $this->getMethod($listener, $attribute->method ?? '__invoke'); |
| 47 | 47 | |
| 48 | 48 | $events = (array)($attribute->event ?? $this->getEventFromTypeDeclaration($method)); |
| 49 | - foreach ($events as $event) { |
|
| 49 | + foreach ($events as $event){ |
|
| 50 | 50 | $this->registry->addListener( |
| 51 | 51 | event: $event, |
| 52 | 52 | listener: $this->factory->create($listener, $method->getName()), |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $attrs = $this->reader->getClassMetadata($class, Listener::class); |
| 63 | 63 | |
| 64 | - foreach ($attrs as $attr) { |
|
| 64 | + foreach ($attrs as $attr){ |
|
| 65 | 65 | $this->attributes[$class->getName()][] = $attr; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - foreach ($class->getMethods() as $method) { |
|
| 68 | + foreach ($class->getMethods() as $method){ |
|
| 69 | 69 | $attrs = $this->reader->getFunctionMetadata($method, Listener::class); |
| 70 | 70 | |
| 71 | - foreach ($attrs as $attr) { |
|
| 71 | + foreach ($attrs as $attr){ |
|
| 72 | 72 | $attr->method = $method->getName(); |
| 73 | 73 | $this->attributes[$class->getName()][] = $attr; |
| 74 | 74 | } |
@@ -26,27 +26,33 @@ discard block |
||
| 26 | 26 | private readonly ?ListenerRegistryInterface $registry = null, |
| 27 | 27 | ) { |
| 28 | 28 | // Look for Spiral\Events\Attribute\Listener attribute only when ListenerRegistry provided by container |
| 29 | - if ($this->registry instanceof \Spiral\Events\ListenerRegistryInterface) { |
|
| 29 | + if ($this->registry instanceof \Spiral\Events\ListenerRegistryInterface) |
|
| 30 | + { |
|
| 30 | 31 | $listenerRegistry->addListener($this); |
| 31 | 32 | } |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | 35 | public function process(): void |
| 35 | 36 | { |
| 36 | - if (!$this->registry instanceof \Spiral\Events\ListenerRegistryInterface) { |
|
| 37 | + if (!$this->registry instanceof \Spiral\Events\ListenerRegistryInterface) |
|
| 38 | + { |
|
| 37 | 39 | return; |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | - if (!$this->collected) { |
|
| 42 | + if (!$this->collected) |
|
| 43 | + { |
|
| 41 | 44 | throw new \RuntimeException(\sprintf('Tokenizer did not finalize %s listener.', self::class)); |
| 42 | 45 | } |
| 43 | 46 | |
| 44 | - foreach ($this->attributes as $listener => $attributes) { |
|
| 45 | - foreach ($attributes as $attribute) { |
|
| 47 | + foreach ($this->attributes as $listener => $attributes) |
|
| 48 | + { |
|
| 49 | + foreach ($attributes as $attribute) |
|
| 50 | + { |
|
| 46 | 51 | $method = $this->getMethod($listener, $attribute->method ?? '__invoke'); |
| 47 | 52 | |
| 48 | 53 | $events = (array)($attribute->event ?? $this->getEventFromTypeDeclaration($method)); |
| 49 | - foreach ($events as $event) { |
|
| 54 | + foreach ($events as $event) |
|
| 55 | + { |
|
| 50 | 56 | $this->registry->addListener( |
| 51 | 57 | event: $event, |
| 52 | 58 | listener: $this->factory->create($listener, $method->getName()), |
@@ -61,14 +67,17 @@ discard block |
||
| 61 | 67 | { |
| 62 | 68 | $attrs = $this->reader->getClassMetadata($class, Listener::class); |
| 63 | 69 | |
| 64 | - foreach ($attrs as $attr) { |
|
| 70 | + foreach ($attrs as $attr) |
|
| 71 | + { |
|
| 65 | 72 | $this->attributes[$class->getName()][] = $attr; |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | - foreach ($class->getMethods() as $method) { |
|
| 75 | + foreach ($class->getMethods() as $method) |
|
| 76 | + { |
|
| 69 | 77 | $attrs = $this->reader->getFunctionMetadata($method, Listener::class); |
| 70 | 78 | |
| 71 | - foreach ($attrs as $attr) { |
|
| 79 | + foreach ($attrs as $attr) |
|
| 80 | + { |
|
| 72 | 81 | $attr->method = $method->getName(); |
| 73 | 82 | $this->attributes[$class->getName()][] = $attr; |
| 74 | 83 | } |