Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MiddlewareAdapter | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
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\Middleware\Psr15; |
| 16 | |
| 17 | use Pop\Middleware\MiddlewareInterface; |
| 18 | use Psr\Http\Server\MiddlewareInterface as Psr15MiddlewareInterface; |
| 19 | |
| 20 | /** |
| 21 | * PSR-15 middleware adapter class |
| 22 | * |
| 23 | * Bridges a real PSR-15 Psr\Http\Server\MiddlewareInterface handler into Pop's |
| 24 | * native middleware queue, translating Pop's handle(mixed $request, \Closure |
| 25 | * $next) call shape into PSR-15's process(ServerRequestInterface $request, |
| 26 | * RequestHandlerInterface $handler) shape. |
| 27 | * |
| 28 | * @category Pop |
| 29 | * @package Pop\Middleware |
| 30 | * @author Nick Sagona, III <nick@popphp.org> |
| 31 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 32 | * @license https://www.popphp.org/license New BSD License |
| 33 | * @version 5.0.0 |
| 34 | */ |
| 35 | class MiddlewareAdapter implements MiddlewareInterface |
| 36 | { |
| 37 | |
| 38 | /** |
| 39 | * PSR-15 middleware |
| 40 | * @var Psr15MiddlewareInterface |
| 41 | */ |
| 42 | protected Psr15MiddlewareInterface $middleware; |
| 43 | |
| 44 | /** |
| 45 | * Constructor |
| 46 | * |
| 47 | * Instantiate the middleware adapter object. |
| 48 | * |
| 49 | * @param Psr15MiddlewareInterface $middleware |
| 50 | */ |
| 51 | public function __construct(Psr15MiddlewareInterface $middleware) |
| 52 | { |
| 53 | $this->middleware = $middleware; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Handle the request |
| 58 | * |
| 59 | * @param mixed $request |
| 60 | * @param \Closure $next |
| 61 | * @return mixed |
| 62 | */ |
| 63 | public function handle(mixed $request, \Closure $next): mixed |
| 64 | { |
| 65 | return $this->middleware->process($request, new RequestHandler($next)); |
| 66 | } |
| 67 | |
| 68 | } |