1 | <?php |
||
16 | class Dispatcher implements MiddlewareInterface, RequestHandlerInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var callable middleware resolver |
||
20 | */ |
||
21 | private $resolver; |
||
22 | |||
23 | /** |
||
24 | * @var mixed[] unresolved middleware stack |
||
25 | */ |
||
26 | private $stack; |
||
27 | |||
28 | /** |
||
29 | * @param (callable|MiddlewareInterface|mixed)[] $stack middleware stack (with at least one middleware component) |
||
30 | * @param callable|null $resolver optional middleware resolver function: receives an element from the |
||
31 | * middleware stack, resolves it and returns a `callable|MiddlewareInterface` |
||
32 | * |
||
33 | * @throws InvalidArgumentException if an empty middleware stack was given |
||
34 | */ |
||
35 | 1 | public function __construct($stack, callable $resolver = null) |
|
44 | |||
45 | /** |
||
46 | * Dispatches the middleware stack and returns the resulting `ResponseInterface`. |
||
47 | * |
||
48 | * @param ServerRequestInterface $request |
||
49 | * |
||
50 | * @return ResponseInterface |
||
51 | * |
||
52 | * @throws LogicException on unexpected result from any middleware on the stack |
||
53 | */ |
||
54 | 1 | public function handle(ServerRequestInterface $request): ResponseInterface |
|
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | 1 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
76 | |||
77 | /** |
||
78 | * @param int $index middleware stack index |
||
79 | * |
||
80 | * @return RequestHandlerInterface |
||
81 | */ |
||
82 | 1 | private function resolve($index): RequestHandlerInterface |
|
116 | } |
||
117 |