| 1 | <?php |
||
| 14 | class Delegate implements RequestHandlerInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var callable |
||
| 18 | */ |
||
| 19 | private $callback; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param callable $callback function (RequestInterface $request) : ResponseInterface |
||
| 23 | */ |
||
| 24 | 1 | public function __construct(callable $callback) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * Dispatch the next available middleware and return the response. |
||
| 31 | * |
||
| 32 | * @param ServerRequestInterface $request |
||
| 33 | * |
||
| 34 | * @return ResponseInterface |
||
| 35 | */ |
||
| 36 | 1 | public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 37 | { |
||
| 38 | 1 | return call_user_func($this->callback, $request); |
|
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Dispatch the next available middleware and return the response. |
||
| 43 | * |
||
| 44 | * This method duplicates `next()` to provide backwards compatibility with non-PSR 15 middleware. |
||
| 45 | * |
||
| 46 | * @param ServerRequestInterface $request |
||
| 47 | * |
||
| 48 | * @return ResponseInterface |
||
| 49 | */ |
||
| 50 | 1 | public function __invoke(ServerRequestInterface $request) |
|
| 54 | } |
||
| 55 |