Passed
Push — master ( bec3a0...d17744 )
by 世昌
01:55
created

RouteCollection::get()   A

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 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\route;
3
4
use Iterator;
5
use ArrayIterator;
6
use nebula\route\collection\CollectionFile;
7
8
/**
9
 * 路由集合
10
 *
11
 */
12
class RouteCollection extends CollectionFile
13
{
14
    /**
15
     * 属性
16
     *
17
     * @var RouteMatcher[]
18
     */
19
    protected $collection = [];
20
21
    /**
22
     * 创建集合
23
     *
24
     * @param RouteMatcher[] $collection
25
     */
26
    public function __construct(array $collection=[])
27
    {
28
        $this->merge($collection);
29
    }
30
31
    /**
32
     * 合并集合
33
     *
34
     * @param array $collection
35
     * @return void
36
     */
37
    public function merge(array $collection=[])
38
    {
39
        $this->collection = array_merge($this->collection, $collection);
40
    }
41
42
    /**
43
     * 添加集合
44
     *
45
     * @param string $name
46
     * @param RouteMatcher $collection
47
     * @return void
48
     */
49
    public function add(string $name, RouteMatcher $collection)
50
    {
51
        $this->collection[$name] = $collection;
52
    }
53
54
    /**
55
     * 获取集合
56
     *
57
     * @param string $name
58
     * @return RouteMatcher|null
59
     */
60
    public function get(string $name):?RouteMatcher
61
    {
62
        return $this->collection[$name] ?? null;
63
    }
64
65
    /**
66
     * 获取迭代器
67
     *
68
     * @return RouteMatcher[]
69
     */
70
    public function getCollection():array
71
    {
72
        return $this->collection;
73
    }
74
}
75