| Total Complexity | 8 |
| Total Lines | 123 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class RouteMatcher |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * 匹配的方法 |
||
| 16 | * |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected $methods; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * 匹配的URI |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $uri; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * 属性 |
||
| 30 | * |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | protected $attribute; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Uri匹配器 |
||
| 37 | * |
||
| 38 | * @var UriMatcher |
||
| 39 | */ |
||
| 40 | protected $matcher; |
||
| 41 | |||
| 42 | |||
| 43 | public function __construct(array $methods, string $uri, array $attribute=[]) |
||
| 44 | { |
||
| 45 | array_walk($methods, function ($value) { |
||
| 46 | return strtoupper($value); |
||
| 47 | }); |
||
| 48 | $this->methods = $methods; |
||
| 49 | $this->uri = $uri; |
||
| 50 | $this->matcher = UriMatcher::build($uri); |
||
| 51 | $this->attribute = $attribute; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Get 属性 |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | public function getAttribute() |
||
| 60 | { |
||
| 61 | return $this->attribute; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set 属性 |
||
| 66 | * |
||
| 67 | * @param array $attribute 属性 |
||
| 68 | * |
||
| 69 | * @return self |
||
| 70 | */ |
||
| 71 | public function setAttribute(array $attribute) |
||
| 72 | { |
||
| 73 | $this->attribute = $attribute; |
||
| 74 | |||
| 75 | return $this; |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Get 匹配的方法 |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | public function getMethods() |
||
| 84 | { |
||
| 85 | return $this->methods; |
||
|
|
|||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Set 匹配的方法 |
||
| 90 | * |
||
| 91 | * @param string $methods 匹配的方法 |
||
| 92 | * |
||
| 93 | * @return self |
||
| 94 | */ |
||
| 95 | public function setMethods(string $methods) |
||
| 96 | { |
||
| 97 | $this->methods = $methods; |
||
| 98 | |||
| 99 | return $this; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Get 匹配的URI |
||
| 104 | * |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | public function getUri() |
||
| 108 | { |
||
| 109 | return $this->uri; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Set 匹配的URI |
||
| 114 | * |
||
| 115 | * @param string $uri 匹配的URI |
||
| 116 | * |
||
| 117 | * @return self |
||
| 118 | */ |
||
| 119 | public function setUri(string $uri) |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Get uri匹配器 |
||
| 128 | * |
||
| 129 | * @return UriMatcher |
||
| 130 | */ |
||
| 131 | public function getMatcher() |
||
| 134 | } |
||
| 135 | } |
||
| 136 |