1 | <?php |
||
13 | class Bamboo implements MiddlewareInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var (callable|MiddlewareInterface)[] |
||
17 | */ |
||
18 | protected $nodes = []; |
||
19 | |||
20 | /** |
||
21 | * Bamboo style PSR-7 middleware pipe. |
||
22 | * |
||
23 | * @param (callable|MiddlewareInterface)[] $nodes the middlewares, which requests pass through |
||
24 | */ |
||
25 | public function __construct(array $nodes) |
||
29 | |||
30 | /** |
||
31 | * Push a middleware onto the end of $nodes type safe. |
||
32 | * |
||
33 | * @param callable|MiddlewareInterface $middleware |
||
34 | */ |
||
35 | private function push(callable $middleware) |
||
39 | |||
40 | /** |
||
41 | * Process an incoming server request and return the response. |
||
42 | * |
||
43 | * @param ServerRequestInterface $request |
||
44 | * @param callable|RequestHandlerInterface $finalHandler |
||
45 | * |
||
46 | * @return ResponseInterface |
||
47 | */ |
||
48 | public function dispatch(ServerRequestInterface $request, callable $finalHandler):ResponseInterface |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function __invoke(ServerRequestInterface $request):Generator |
||
62 | |||
63 | /** |
||
64 | * Process an incoming server request by delegating it to the middleware specified by $index. |
||
65 | * |
||
66 | * @param int $index the $nodes index |
||
67 | * @param ServerRequestInterface $request |
||
68 | * |
||
69 | * @return Generator |
||
70 | */ |
||
71 | protected function processMiddleware(int $index, ServerRequestInterface $request):Generator |
||
95 | } |
||
96 |