Completed
Push — master ( 6b8416...c520c0 )
by Filipe
02:12
created

SessionMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 5 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 Interop\Http\Server\MiddlewareInterface;
13
use Interop\Http\Server\RequestHandlerInterface;
14
use Psr\Http\Message\ResponseInterface;
15
use Psr\Http\Message\ServerRequestInterface;
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)
49
    {
50
        $request = $request->withAttribute('sessionDriver', $this->sessionDriver);
51
        return $handler->handle($request);
52
    }
53
}