Records::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Router records
4
 * User: moyo
5
 * Date: 2018/5/29
6
 * Time: 11:23 AM
7
 */
8
9
namespace Carno\Web\Router;
10
11
use FastRoute\DataGenerator\GroupCountBased as GCBGenerator;
12
use FastRoute\Dispatcher;
13
use FastRoute\Dispatcher\GroupCountBased as GCBDispatcher;
14
use FastRoute\RouteCollector;
15
use FastRoute\RouteParser\Std;
16
17
class Records
18
{
19
    /**
20
     * @var RouteCollector
21
     */
22
    private $collector = null;
23
24
    /**
25
     * @var Dispatcher
26
     */
27
    private $dispatcher = null;
28
29
    /**
30
     * Records constructor.
31
     */
32
    public function __construct()
33
    {
34
        $this->collector = new RouteCollector(new Std, new GCBGenerator);
35
    }
36
37
    /**
38
     * @return Dispatcher
39
     */
40
    public function dispatcher() : Dispatcher
41
    {
42
        return $this->dispatcher ?? $this->dispatcher = new GCBDispatcher($this->collector->getData());
43
    }
44
45
    /**
46
     * @param string $method
47
     * @param string $uri
48
     * @param callable $processor
49
     */
50
    public function accept(string $method, string $uri, callable $processor) : void
51
    {
52
        $this->collector->addRoute($method, $uri, $processor);
53
    }
54
}
55