1 | <?php |
||
16 | class ContainerMiddlewareChain implements MiddlewareChain |
||
17 | { |
||
18 | /** |
||
19 | * @var ContainerInterface |
||
20 | */ |
||
21 | private $container; |
||
22 | |||
23 | /** |
||
24 | * @var string[] |
||
25 | */ |
||
26 | private $middleware_ids = []; |
||
27 | |||
28 | /** |
||
29 | * @param ContainerInterface $container |
||
30 | */ |
||
31 | 2 | public function __construct(ContainerInterface $container) |
|
35 | |||
36 | /** |
||
37 | * @param string $service |
||
38 | */ |
||
39 | 1 | public function registerService($service) |
|
40 | { |
||
41 | 1 | $index = array_search($service, $this->middleware_ids); |
|
42 | |||
43 | // move existing middleware to end of chain |
||
44 | 1 | if ($index !== false) { |
|
45 | 1 | unset($this->middleware_ids[$index]); |
|
46 | // correct array indexes |
||
47 | 1 | $this->middleware_ids = array_values($this->middleware_ids); |
|
48 | 1 | } |
|
49 | |||
50 | 1 | $this->middleware_ids[] = $service; |
|
51 | 1 | } |
|
52 | |||
53 | /** |
||
54 | * @param mixed $message |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | 2 | public function run($message) |
|
62 | |||
63 | /** |
||
64 | * @param int $index |
||
65 | * |
||
66 | * @return callable |
||
67 | */ |
||
68 | 2 | private function call($index) |
|
82 | |||
83 | /** |
||
84 | * @param $index |
||
85 | * |
||
86 | * @return Middleware |
||
87 | */ |
||
88 | 2 | private function lazyLoad($index) |
|
100 | } |
||
101 |