1 | <?php declare(strict_types=1); |
||
13 | final class Middleware implements MiddlewareInterface |
||
14 | { |
||
15 | use ErrorTrait; |
||
16 | |||
17 | const HEADER = 'X-Middleware-Timer-Response-Body'; |
||
18 | |||
19 | /** |
||
20 | * @var float |
||
21 | */ |
||
22 | private $time; |
||
23 | |||
24 | /** |
||
25 | * Return the processed $request via a fulfilled promise. |
||
26 | * When implementing cache or other feature that returns a response, do it with a rejected promise. |
||
27 | * If neither is possible, e.g. on some kind of failure, resolve the unaltered request. |
||
28 | * |
||
29 | * @param RequestInterface $request |
||
30 | * @param array $options |
||
31 | * @return CancellablePromiseInterface |
||
32 | */ |
||
33 | 1 | public function pre(RequestInterface $request, array $options = []): CancellablePromiseInterface |
|
39 | |||
40 | /** |
||
41 | * Return the processed $response via a promise. |
||
42 | * |
||
43 | * @param ResponseInterface $response |
||
44 | * @param array $options |
||
45 | * @return CancellablePromiseInterface |
||
46 | */ |
||
47 | 1 | public function post(ResponseInterface $response, array $options = []): CancellablePromiseInterface |
|
53 | |||
54 | /** |
||
55 | * Priority ranging from 0 to 1000. Where 1000 will be executed first on `pre` and 0 last on `pre`. |
||
56 | * For `post` the order is reversed. |
||
57 | * |
||
58 | * @return int |
||
59 | */ |
||
60 | public function priority(): int |
||
64 | } |
||
65 |