Completed
Push — master ( a9f59f...72efb5 )
by Vítor
16:45
created

RouteMatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * ZfDebugModule. Console commands and other utilities 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
    public function __construct(RouteStackInterface $router)
28
    {
29
        $this->router = $router;
30
    }
31
32
    /**
33
     * @param string $method
34
     * @param string $url
35
     * @return null|string
36
     */
37
    public function match($method, $url)
38
    {
39
        $request = new Request();
40
        $request->setMethod($method);
41
        $request->setUri($url);
42
43
        $routeMatch = $this->router->match($request);
44
        return ($routeMatch instanceof RouteMatch) ? $routeMatch->getMatchedRouteName() : null;
45
    }
46
}