functions.php ➔ dispatcher()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 2
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use zqhong\route\RouteCollector;
4
use zqhong\route\RouteDispatcher;
5
use zqhong\route\RouteGenerator;
6
use zqhong\route\RouteParser;
7
8
if (!function_exists('dispatcher')) {
9
    function dispatcher(callable $callback, array $options = [])
10
    {
11
        $options += [
12
            'routeParser' => RouteParser::class,
13
            'routeGenerator' => RouteGenerator::class,
14
            'dispatcher' => RouteDispatcher::class,
15
            'routeCollector' => RouteCollector::class,
16
        ];
17
18
        $routeCollector = new $options['routeCollector'](
19
            new $options['routeParser'], new $options['routeGenerator']
20
        );
21
        $callback($routeCollector);
22
23
        return new $options['dispatcher']($routeCollector);
24
    }
25
}
26