SessionMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 2
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of slick/http
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Slick\Http\Server\Middleware;
13
14
use Psr\Http\Server\MiddlewareInterface;
15
use Psr\Http\Message\ResponseInterface;
16
use Psr\Http\Message\ServerRequestInterface;
17
use Psr\Http\Server\RequestHandlerInterface;
18
use Slick\Http\Session\SessionDriverInterface;
19
20
/**
21
 * SessionMiddleware
22
 *
23
 * @package Slick\Http\Server\Middleware
24
*/
25
class SessionMiddleware implements MiddlewareInterface
26
{
27
    /**
28
     * @var SessionDriverInterface
29
     */
30
    private $sessionDriver;
31
32
    /**
33
     * SessionMiddleware constructor.
34
     * @param SessionDriverInterface $sessionDriver
35
     */
36
    public function __construct(SessionDriverInterface $sessionDriver)
37
    {
38
        $this->sessionDriver = $sessionDriver;
39
    }
40
41
    /**
42
     * Process an incoming server request and return a response, optionally delegating
43
     * response creation to a handler.
44
     *
45
     * @param ServerRequestInterface $request
46
     * @param RequestHandlerInterface $handler
47
     *
48
     * @return ResponseInterface
49
     */
50
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
51
    {
52
        $request = $request->withAttribute('sessionDriver', $this->sessionDriver);
53
        return $handler->handle($request);
54
    }
55
}
56