Completed
Pull Request — 1.x (#214)
by Yuu
03:24 queued 55s
created

WebRouter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156
Metric Value
dl 0
loc 5
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1.0156
1
<?php
2
/**
3
 * This file is part of the BEAR.Sunday package
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package\Provide\Router;
8
9
use BEAR\Sunday\Annotation\DefaultSchemeHost;
10
use BEAR\Sunday\Extension\Router\RouterInterface;
11
use BEAR\Sunday\Extension\Router\RouterMatch;
12
13
class WebRouter implements RouterInterface, WebRouterInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $schemeHost;
19
20
    /**
21
     * @var HttpMethodParamsInterface
22
     */
23
    private $httpMethodParams;
24
25
    /**
26
     * @param string                    $schemeHost
27
     * @param HttpMethodParamsInterface $httpMethodParams
28
     *
29
     * @DefaultSchemeHost("schemeHost")
30
     */
31 24
    public function __construct($schemeHost, HttpMethodParamsInterface $httpMethodParams)
32
    {
33 24
        $this->schemeHost = $schemeHost;
34 24
        $this->httpMethodParams = $httpMethodParams;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 8
    public function match(array $globals, array $server)
41
    {
42
        $request = new RouterMatch;
43
        list($request->method, $request->query) = $this->httpMethodParams->get($server, $globals['_GET'], $globals['_POST']);
44
        $request->path = $this->schemeHost . parse_url($server['REQUEST_URI'], PHP_URL_PATH);
45
46 8
        return $request;
47 8
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 3
    public function generate($name, $data)
53
    {
54 3
        return false;
55
    }
56
}
57