Completed
Push — master ( b01c18...6c15ba )
by Hong
06:44
created

Phossa2RouteMiddleware::after()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Middleware
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Middleware\Middleware;
16
17
use Phossa2\Route\Dispatcher;
18
use Psr\Http\Message\RequestInterface;
19
use Psr\Http\Message\ResponseInterface;
20
21
/**
22
 * Phossa2RouteMiddleware
23
 *
24
 * Using phossa2/route to dispatching
25
 *
26
 * @package Phossa2\Middleware
27
 * @author  Hong Zhang <[email protected]>
28
 * @see     MiddlewareAbstract
29
 * @version 2.0.0
30
 * @since   2.0.0 added
31
 */
32
class Phossa2RouteMiddleware extends MiddlewareAbstract
33
{
34
    /**
35
     * @var    Dispatcher
36
     * @access protected
37
     */
38
    protected $dispatcher;
39
40
    /**
41
     * @param  Dispatcher $dispatcher
42
     * @access public
43
     */
44
    public function __construct(Dispatcher $dispatcher)
45
    {
46
        $this->dispatcher = $dispatcher;
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    protected function before(
53
        RequestInterface $request,
54
        ResponseInterface $response
55
    )/* : ResponseInterface */ {
56
        $this->dispatcher->dispatch(
57
            $request->getMethod(),
58
            $request->getUri()->getPath(),
59
            ['request' => $request, 'response' => $response]
60
        );
61
62
        // response in the result
63
        return $this->dispatcher->getResult()->getParameters()['response'];
64
    }
65
}
66