DispatchMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 3
1
<?php
2
3
/**
4
 * @author Jared King <[email protected]>
5
 *
6
 * @link http://jaredtking.com
7
 *
8
 * @copyright 2015 Jared King
9
 * @license MIT
10
 */
11
namespace Infuse\Middleware;
12
13
use FastRoute\Dispatcher;
14
use Infuse\HasApp;
15
use Infuse\Request;
16
use Infuse\Response;
17
18
class DispatchMiddleware
19
{
20
    use HasApp;
21
22
    public function __invoke(Request $req, Response $res, callable $next)
23
    {
24
        $routeInfo = $this->app['routeInfo'];
25
26
        // resolve the route
27
        if ($routeInfo[0] === Dispatcher::FOUND) {
28
            return $this->app['route_resolver']->resolve($routeInfo[1], $req, $res, $routeInfo[2]);
29
        }
30
31
        // handle 405 Method Not Allowed errors
32
        if ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
33
            return $this->app['method_not_allowed_handler']($req, $res, $routeInfo[1]);
34
        }
35
36
        // handle 404 Not Found errors
37
        return $this->app['not_found_handler']($req, $res);
38
    }
39
}
40