1 | <?php |
||
21 | class Pipe implements MiddlewareInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var MiddlewareInterface[] |
||
25 | */ |
||
26 | private $middlewares; |
||
27 | |||
28 | /** |
||
29 | * Dispatcher constructor. |
||
30 | * |
||
31 | * @param MiddlewareInterface[] $middlewares |
||
32 | */ |
||
33 | public function __construct(array $middlewares = []) |
||
37 | |||
38 | /** |
||
39 | * Appends new middleware for this message bus. Should only be used at configuration time. |
||
40 | * |
||
41 | * @param MiddlewareInterface $middleware |
||
42 | */ |
||
43 | public function appendMiddleware(MiddlewareInterface $middleware) |
||
47 | |||
48 | /** |
||
49 | * Prepends new middleware for this message bus. Should only be used at configuration time. |
||
50 | * |
||
51 | * @param MiddlewareInterface $middleware |
||
52 | */ |
||
53 | public function prependMiddleware(MiddlewareInterface $middleware) |
||
57 | |||
58 | /** |
||
59 | * @param MiddlewareInterface $middleware |
||
60 | */ |
||
61 | public function addMiddlewareAfterFirstOne(MiddlewareInterface $middleware) |
||
69 | |||
70 | /** |
||
71 | * @param MiddlewareInterface $middleware |
||
72 | */ |
||
73 | public function addMiddlewareBeforeLastOne(MiddlewareInterface $middleware) |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
97 | |||
98 | /** |
||
99 | * Dispatches the middleware and returns the resulting `ResponseInterface`. |
||
100 | * |
||
101 | * @param ServerRequestInterface $request |
||
102 | * |
||
103 | * @throws \LogicException on unexpected result from any middleware on the middlewares |
||
104 | * |
||
105 | * @return ResponseInterface |
||
106 | */ |
||
107 | public function dispatch(ServerRequestInterface $request) |
||
113 | |||
114 | /** |
||
115 | * @param int $index Middleware index |
||
116 | * |
||
117 | * @return RequestHandlerInterface |
||
118 | */ |
||
119 | private function resolve(int $index): RequestHandlerInterface |
||
133 | } |
||
134 |