1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Spiral\Interceptors\Handler; |
6
|
|
|
|
7
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
8
|
|
|
use Spiral\Interceptors\Context\CallContext; |
9
|
|
|
use Spiral\Interceptors\Event\InterceptorCalling; |
10
|
|
|
use Spiral\Interceptors\Exception\InterceptorException; |
11
|
|
|
use Spiral\Interceptors\HandlerInterface; |
12
|
|
|
use Spiral\Interceptors\InterceptorInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Interceptor pipeline. |
16
|
|
|
* |
17
|
|
|
* WARNING: make sure you don't use any legacy interceptors because they aren't supported with this pipeline. |
18
|
|
|
*/ |
19
|
|
|
final class InterceptorPipeline implements HandlerInterface |
20
|
|
|
{ |
21
|
|
|
private ?HandlerInterface $handler = null; |
22
|
|
|
|
23
|
|
|
/** @var list<InterceptorInterface> */ |
|
|
|
|
24
|
|
|
private array $interceptors = []; |
25
|
|
|
|
26
|
|
|
private int $position = 0; |
27
|
|
|
|
28
|
5 |
|
public function __construct( |
29
|
|
|
private readonly ?EventDispatcherInterface $dispatcher = null |
30
|
|
|
) { |
31
|
5 |
|
} |
32
|
|
|
|
33
|
3 |
|
public function addInterceptor(InterceptorInterface $interceptor): void |
34
|
|
|
{ |
35
|
3 |
|
$this->interceptors[] = $interceptor; |
36
|
|
|
} |
37
|
|
|
|
38
|
3 |
|
public function withHandler(HandlerInterface $handler): self |
39
|
|
|
{ |
40
|
3 |
|
$pipeline = clone $this; |
41
|
3 |
|
$pipeline->handler = $handler; |
42
|
3 |
|
return $pipeline; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @throws \Throwable |
47
|
|
|
*/ |
48
|
5 |
|
public function handle(CallContext $context): mixed |
49
|
|
|
{ |
50
|
5 |
|
if ($this->handler === null) { |
51
|
2 |
|
throw new InterceptorException('Unable to invoke pipeline without last handler.'); |
52
|
|
|
} |
53
|
|
|
|
54
|
3 |
|
if (isset($this->interceptors[$this->position])) { |
55
|
3 |
|
$interceptor = $this->interceptors[$this->position]; |
56
|
|
|
|
57
|
3 |
|
$this->dispatcher?->dispatch(new InterceptorCalling(context: $context, interceptor: $interceptor)); |
58
|
|
|
|
59
|
3 |
|
return $interceptor->intercept($context, $this->next()); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
return $this->handler->handle($context); |
63
|
|
|
} |
64
|
|
|
|
65
|
3 |
|
private function next(): self |
66
|
|
|
{ |
67
|
3 |
|
$pipeline = clone $this; |
68
|
3 |
|
++$pipeline->position; |
69
|
3 |
|
return $pipeline; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths