1 | <?php |
||
10 | class Routes implements RoutesInterface |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * route list as array |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | private $routes = []; |
||
19 | |||
20 | /** |
||
21 | * __construct |
||
22 | * |
||
23 | * @param array $routesConfig |
||
24 | */ |
||
25 | 5 | public function __construct(array $routesConfig = []) |
|
26 | { |
||
27 | 5 | if (!empty($routesConfig)) { |
|
28 | 5 | $this->set($routesConfig); |
|
29 | } |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * set routes as array and stack Route collection |
||
34 | * |
||
35 | * @param array $routesConfig |
||
36 | * @return RoutesInterface |
||
37 | */ |
||
38 | 5 | public function set(array $routesConfig): RoutesInterface |
|
45 | |||
46 | /** |
||
47 | * returns routes as array |
||
48 | * |
||
49 | * @return array |
||
50 | */ |
||
51 | 1 | public function get(): array |
|
55 | |||
56 | /** |
||
57 | * returns routes as array |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | 2 | public function getExpr(): array |
|
62 | { |
||
63 | 2 | $patterns = array_map( |
|
64 | function (Route $i) { |
||
65 | 2 | return $i->getExpr(); |
|
66 | 2 | }, |
|
67 | 2 | $this->routes |
|
68 | ); |
||
69 | 2 | return $patterns; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * stacks routes as Route object collection from routes config |
||
74 | * |
||
75 | * @param array $routesConfig |
||
76 | * @return RoutesInterface |
||
77 | */ |
||
78 | 1 | protected function prepare(array $routesConfig): RoutesInterface |
|
86 | |||
87 | /** |
||
88 | * validate routes to be an array of regexp string |
||
89 | * |
||
90 | * @throws Exception |
||
91 | */ |
||
92 | 2 | protected function validate() |
|
102 | |||
103 | /** |
||
104 | * return true if regexp is invalid |
||
105 | * |
||
106 | * @param string $regExp |
||
107 | * @return boolean |
||
108 | */ |
||
109 | protected function isInvalidRegexp(string $regExp): bool |
||
114 | } |
||
115 |
If you suppress an error, we recommend checking for the error condition explicitly: