1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Queue\Middleware\FailureHandling; |
6
|
|
|
|
7
|
|
|
use Closure; |
8
|
|
|
|
9
|
|
|
final class MiddlewareFailureStack implements MessageFailureHandlerInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Contains a stack of middleware wrapped in handlers. |
13
|
|
|
* Each handler points to the handler of middleware that will be processed next. |
14
|
|
|
* |
15
|
|
|
* @var MessageFailureHandlerInterface|null stack of middleware |
16
|
|
|
*/ |
17
|
|
|
private ?MessageFailureHandlerInterface $stack = null; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param Closure[] $middlewares Middlewares. |
21
|
|
|
* @param MessageFailureHandlerInterface $finishHandler Fallback handler |
22
|
|
|
* events. |
23
|
|
|
*/ |
24
|
8 |
|
public function __construct( |
25
|
|
|
private array $middlewares, |
26
|
|
|
private MessageFailureHandlerInterface $finishHandler, |
27
|
|
|
) { |
28
|
8 |
|
} |
29
|
|
|
|
30
|
8 |
|
public function handleFailure(FailureHandlingRequest $request): FailureHandlingRequest |
31
|
|
|
{ |
32
|
8 |
|
if ($this->stack === null) { |
33
|
8 |
|
$this->build(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** @psalm-suppress PossiblyNullReference */ |
37
|
8 |
|
return $this->stack->handleFailure($request); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
8 |
|
private function build(): void |
41
|
|
|
{ |
42
|
8 |
|
$handler = $this->finishHandler; |
43
|
|
|
|
44
|
8 |
|
foreach ($this->middlewares as $middleware) { |
45
|
7 |
|
$handler = $this->wrap($middleware, $handler); |
46
|
|
|
} |
47
|
|
|
|
48
|
8 |
|
$this->stack = $handler; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Wrap handler by middlewares. |
53
|
|
|
*/ |
54
|
7 |
|
private function wrap(Closure $middlewareFactory, MessageFailureHandlerInterface $handler): MessageFailureHandlerInterface |
55
|
|
|
{ |
56
|
7 |
|
return new class ($middlewareFactory, $handler) implements MessageFailureHandlerInterface { |
57
|
|
|
private ?MiddlewareFailureInterface $middleware = null; |
58
|
|
|
|
59
|
|
|
public function __construct( |
60
|
|
|
private Closure $middlewareFactory, |
61
|
|
|
private MessageFailureHandlerInterface $handler, |
62
|
|
|
) { |
63
|
7 |
|
} |
64
|
|
|
|
65
|
|
|
public function handleFailure(FailureHandlingRequest $request): FailureHandlingRequest |
66
|
|
|
{ |
67
|
7 |
|
if ($this->middleware === null) { |
68
|
7 |
|
$this->middleware = ($this->middlewareFactory)(); |
69
|
|
|
} |
70
|
|
|
|
71
|
7 |
|
return $this->middleware->processFailure($request, $this->handler); |
|
|
|
|
72
|
|
|
} |
73
|
7 |
|
}; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.