1 | <?php |
||
10 | class Stack implements DelegateInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var callable |
||
14 | */ |
||
15 | private $default; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $middleware = []; |
||
21 | |||
22 | /** |
||
23 | * @var integer |
||
24 | */ |
||
25 | private $index = 0; |
||
26 | |||
27 | /** |
||
28 | * @param callable $default to call when no middleware is available |
||
29 | * @param array $middleware |
||
30 | */ |
||
31 | 3 | public function __construct(callable $default, ...$middleware) |
|
36 | |||
37 | /** |
||
38 | * Add a middleware to the end of the stack. |
||
39 | * |
||
40 | * @param ServerMiddlewareInterface $middleware |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | 1 | public function append(ServerMiddlewareInterface $middleware) |
|
48 | |||
49 | /** |
||
50 | * Add a middleware to the beginning of the stack. |
||
51 | * |
||
52 | * @param ServerMiddlewareInterface $middleware |
||
53 | * |
||
54 | * @return void |
||
55 | */ |
||
56 | 1 | public function prepend(ServerMiddlewareInterface $middleware) |
|
60 | |||
61 | /** |
||
62 | * Process the request using the current middleware. |
||
63 | * |
||
64 | * @param RequestInterface $request |
||
65 | * |
||
66 | * @return ResponseInterface |
||
67 | */ |
||
68 | 2 | public function process(RequestInterface $request) |
|
76 | |||
77 | /** |
||
78 | * Get a delegate pointing to the next middleware. |
||
79 | * |
||
80 | * @return static |
||
81 | */ |
||
82 | 1 | private function nextDelegate() |
|
89 | |||
90 | /** |
||
91 | * Dispatch the middleware stack. |
||
92 | * |
||
93 | * @param RequestInterface $request |
||
94 | * |
||
95 | * @return ResponseInterface |
||
96 | */ |
||
97 | 2 | public function dispatch(RequestInterface $request) |
|
101 | } |
||
102 |