Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CallableMiddleware | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| process | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Http\Client\Middleware; |
| 16 | |
| 17 | use Psr\Http\Message\RequestInterface; |
| 18 | use Psr\Http\Message\ResponseInterface; |
| 19 | |
| 20 | /** |
| 21 | * Adapts a plain callable into a MiddlewareInterface, so Client::addMiddleware() |
| 22 | * can accept a closure directly instead of requiring a full class |
| 23 | * |
| 24 | * @category Pop |
| 25 | * @package Pop\Http |
| 26 | * @author Nick Sagona, III <nick@popphp.org> |
| 27 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 28 | * @license https://www.popphp.org/license New BSD License |
| 29 | * @version 6.0.0 |
| 30 | */ |
| 31 | class CallableMiddleware implements MiddlewareInterface |
| 32 | { |
| 33 | |
| 34 | /** |
| 35 | * The wrapped callable |
| 36 | * @var callable |
| 37 | */ |
| 38 | protected $callable; |
| 39 | |
| 40 | /** |
| 41 | * Constructor |
| 42 | * |
| 43 | * @param callable $callable |
| 44 | */ |
| 45 | public function __construct(callable $callable) |
| 46 | { |
| 47 | $this->callable = $callable; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Process the request by delegating to the wrapped callable |
| 52 | * |
| 53 | * @param RequestInterface $request |
| 54 | * @param RequestHandlerInterface $handler |
| 55 | * @return ResponseInterface |
| 56 | */ |
| 57 | public function process(RequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 58 | { |
| 59 | return ($this->callable)($request, $handler); |
| 60 | } |
| 61 | |
| 62 | } |