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