1 | <?php |
||
18 | final class Chain implements Handler |
||
19 | { |
||
20 | /** |
||
21 | * @var Sequence |
||
22 | */ |
||
23 | private $iterator; |
||
24 | |||
25 | /** |
||
26 | * @var Stage |
||
27 | */ |
||
28 | private $stage; |
||
29 | |||
30 | /** |
||
31 | * @var Handler[] |
||
32 | */ |
||
33 | private $handlers; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | private $count; |
||
39 | |||
40 | /** |
||
41 | * Init chain. |
||
42 | */ |
||
43 | 2 | public function __construct() |
|
50 | |||
51 | /** |
||
52 | * @param Handler $handler |
||
53 | * |
||
54 | * @return Chain |
||
55 | */ |
||
56 | 2 | public function push(Handler $handler): self |
|
63 | |||
64 | /** |
||
65 | * Picks handler by index. |
||
66 | * |
||
67 | * @param int $index |
||
68 | * |
||
69 | * @return Handler |
||
70 | */ |
||
71 | 2 | public function pick(int $index): Handler |
|
75 | |||
76 | /** |
||
77 | * @param mixed $payload |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 2 | public function process($payload) |
|
88 | |||
89 | /** |
||
90 | * Allows reuse the chain as handler of the another. |
||
91 | * |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 1 | public function handle($payload, Stage $next) |
|
98 | } |
||
99 |