PsrConfigMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 6 1
1
<?php
2
3
/**
4
 * PsrAjaxMiddleware.php
5
 *
6
 * A Psr7 middleware to process Jaxon ajax requests.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2022 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Request\Handler\Psr;
16
17
use Jaxon\Di\Container;
18
use Jaxon\Exception\SetupException;
19
use Psr\Http\Message\ResponseInterface;
20
use Psr\Http\Message\ServerRequestInterface;
21
use Psr\Http\Server\MiddlewareInterface;
22
use Psr\Http\Server\RequestHandlerInterface;
23
24
class PsrConfigMiddleware implements MiddlewareInterface
25
{
26
    /**
27
     * @var Container
28
     */
29
    protected $di;
30
31
    /**
32
     * @var string
33
     */
34
    protected $sConfigFile;
35
36
    /**
37
     * The constructor
38
     *
39
     * @param Container $di
40
     * @param string $sConfigFile
41
     */
42
    public function __construct(Container $di, string $sConfigFile)
43
    {
44
        $this->di = $di;
45
        $this->sConfigFile = $sConfigFile;
46
    }
47
48
    /**
49
     * @inheritDoc
50
     * @throws SetupException
51
     */
52
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
53
    {
54
        // Load the config
55
        $this->di->getApp()->setup($this->sConfigFile);
56
        // Next
57
        return $handler->handle($request);
58
    }
59
}
60