|
1
|
|
|
<?php |
|
2
|
|
|
namespace nebula\application\route; |
|
3
|
|
|
|
|
4
|
|
|
use nebula\application\NameFinder; |
|
|
|
|
|
|
5
|
|
|
use nebula\component\route\RouteMatcher; |
|
6
|
|
|
use nebula\component\route\RouteCollection; |
|
7
|
|
|
use nebula\component\cacheable\CacheableTrait; |
|
8
|
|
|
use nebula\component\cacheable\CacheableInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* 应用 |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
class GroupRoutes implements CacheableInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use CacheableTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* 路由集合 |
|
20
|
|
|
* |
|
21
|
|
|
* @var RouteCollection[] |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $routes = []; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* 默认分组 |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $default = 'global:'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* 组名 |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $name; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* 分组名 |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $name |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(string $name) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->name = $name; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* 注册路由 |
|
51
|
|
|
* |
|
52
|
|
|
* @param string|null $module 模块名 |
|
53
|
|
|
* @param string $name 路由名 |
|
54
|
|
|
* @param RouteMatcher $router 路由匹配 |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
|
|
public function add(?string $module = null, string $name, RouteMatcher $router) |
|
58
|
|
|
{ |
|
59
|
|
|
$module = $module ?: $this->default; |
|
60
|
|
|
if (\array_key_exists($module, $this->routes)) { |
|
61
|
|
|
$this->routes[$module]->add($name, $router); |
|
62
|
|
|
} else { |
|
63
|
|
|
$this->routes[$module] = new RouteCollection([$name => $router]); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* 合并路由组 |
|
69
|
|
|
* |
|
70
|
|
|
* @param GroupRoutes $routes |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
public function merge(GroupRoutes $routes) |
|
74
|
|
|
{ |
|
75
|
|
|
$name = $routes->name; |
|
76
|
|
|
if (\array_key_exists($name, $this->routes)) { |
|
77
|
|
|
$this->routes[$name]->merge($routes->routes); |
|
|
|
|
|
|
78
|
|
|
} else { |
|
79
|
|
|
$this->routes[$name] = $routes; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* 搜索路由 |
|
85
|
|
|
* |
|
86
|
|
|
* @param string|null $module |
|
87
|
|
|
* @param string $name |
|
88
|
|
|
* @param string|null $default |
|
89
|
|
|
* @return RouteMatcher|null |
|
90
|
|
|
*/ |
|
91
|
|
|
public function find(?string $module = null, string $name, ?string $default = null):?RouteMatcher |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$module = $module ?: $this->default; |
|
94
|
|
|
if (\array_key_exists($module, $this->routes)) { |
|
95
|
|
|
return $this->routes[$module]->get($name); |
|
96
|
|
|
} |
|
97
|
|
|
return null; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getCacheProperty():array |
|
101
|
|
|
{ |
|
102
|
|
|
return ['routes']; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getCacheKey():string |
|
106
|
|
|
{ |
|
107
|
|
|
return 'routes:'.$this->name; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths