RouteMatcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * ZfDebugModule. WebUI and Console commands for debugging ZF2 apps.
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.html MIT License
6
 * @copyright 2016 Vítor Brandão <[email protected]>
7
 */
8
9
namespace Noiselabs\ZfDebugModule\Util\Routing;
10
11
use Zend\Http\Request;
12
use Zend\Mvc\Router\RouteMatch;
13
use Zend\Mvc\Router\RouteStackInterface;
14
15
class RouteMatcher
16
{
17
    /**
18
     * @var RouteStackInterface
19
     */
20
    private $router;
21
22
    /**
23
     * RouteMatcher constructor.
24
     *
25
     * @param RouteStackInterface $router
26
     */
27 11
    public function __construct(RouteStackInterface $router)
28
    {
29 11
        $this->router = $router;
30 11
    }
31
32
    /**
33
     * @param string $method
34
     * @param string $url
35
     *
36
     * @return null|string
37
     */
38 5
    public function match($method, $url)
39
    {
40 5
        $request = new Request();
41 5
        $request->setMethod($method);
42 5
        $request->setUri($url);
43
44 5
        $routeMatch = $this->router->match($request);
45
46 5
        return ($routeMatch instanceof RouteMatch) ? $routeMatch->getMatchedRouteName() : null;
47
    }
48
}
49