Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CallableRequestHandler
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(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 */
15namespace Pop\Http\Client\Middleware;
16
17use Psr\Http\Message\RequestInterface;
18use Psr\Http\Message\ResponseInterface;
19
20/**
21 * Adapts a plain callable into a RequestHandlerInterface. Internal - used by
22 * Pipeline to build each link of the chain; not part of the API a middleware
23 * author interacts with directly.
24 *
25 * @category   Pop
26 * @package    Pop\Http
27 * @author     Nick Sagona, III <nick@popphp.org>
28 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
29 * @license    https://www.popphp.org/license     New BSD License
30 * @version    6.0.0
31 */
32class CallableRequestHandler implements RequestHandlerInterface
33{
34
35    /**
36     * The wrapped callable
37     * @var callable
38     */
39    protected $callable;
40
41    /**
42     * Constructor
43     *
44     * @param callable $callable
45     */
46    public function __construct(callable $callable)
47    {
48        $this->callable = $callable;
49    }
50
51    /**
52     * Handle the request by delegating to the wrapped callable
53     *
54     * @param  RequestInterface $request
55     * @return ResponseInterface
56     */
57    public function handle(RequestInterface $request): ResponseInterface
58    {
59        return ($this->callable)($request);
60    }
61
62}