@@ -77,15 +77,22 @@ class RuleGroup extends Rule
7777 * @param string $name 分组名称
7878 * @param mixed $rule 分组路由
7979 * @param bool $lazy 延迟解析
80- * @param string $sub 分组子目录
8180 */
82- public function __construct (Route $ router , ?RuleGroup $ parent = null , string $ name = '' , $ rule = null , bool $ lazy = false , string $ sub = '' )
81+ public function __construct (Route $ router , ?RuleGroup $ parent = null , string $ name = '' , $ rule = null , bool $ lazy = false )
8382 {
8483 $ this ->router = $ router ;
8584 $ this ->parent = $ parent ;
8685 $ this ->rule = $ rule ;
8786 $ this ->name = trim ($ name , '/ ' );
88- $ this ->sub = $ sub ;
87+
88+ if ($ name && is_string ($ rule ) || is_null ($ rule )) {
89+ if (is_subclass_of ($ rule , Dispatch::class, false )) {
90+ $ this ->dispatcher ($ rule );
91+ $ this ->rule = '' ;
92+ } else {
93+ $ this ->sub = $ rule ?: $ this ->name ;
94+ }
95+ }
8996
9097 $ this ->setFullName ();
9198
@@ -95,7 +102,7 @@ public function __construct(Route $router, ?RuleGroup $parent = null, string $na
95102 }
96103
97104 if (!$ lazy ) {
98- $ this ->parseGroupRule ($ rule );
105+ $ this ->parseGroupRule ();
99106 }
100107 }
101108
@@ -113,7 +120,7 @@ protected function setFullName(): void
113120 if ($ this ->parent && $ this ->parent ->getFullName ()) {
114121 $ this ->fullName = $ this ->parent ->getFullName () . ($ this ->name ? '/ ' . $ this ->name : '' );
115122 if ($ this ->sub ) {
116- $ this ->sub = $ this ->parent ->getFullName () . '/ ' . $ this ->sub ;
123+ $ this ->sub = $ this ->parent ->getFullName () . '/ ' . $ this ->sub ;
117124 }
118125 } else {
119126 $ this ->fullName = $ this ->name ;
@@ -178,7 +185,7 @@ public function check(Request $request, string $url, bool $completeMatch = false
178185
179186 // 解析分组路由
180187 if (!$ this ->hasParsed ) {
181- $ this ->parseGroupRule ($ this -> rule );
188+ $ this ->parseGroupRule ();
182189 }
183190
184191 // 获取当前路由规则
@@ -270,23 +277,15 @@ public function alias(string $alias)
270277 /**
271278 * 解析分组和域名的路由规则及绑定
272279 * @access public
273- * @param mixed $rule 路由规则
274280 * @return void
275281 */
276- public function parseGroupRule ($ rule ): void
282+ public function parseGroupRule (): void
277283 {
278- if (is_string ($ rule ) && is_subclass_of ($ rule , Dispatch::class)) {
279- $ this ->dispatcher ($ rule );
280- return ;
281- }
282-
283284 $ origin = $ this ->router ->getGroup ();
284285 $ this ->router ->setGroup ($ this );
285286
286- if ($ rule instanceof Closure) {
287- Container::getInstance ()->invokeFunction ($ rule );
288- } elseif (is_string ($ rule ) && $ rule ) {
289- $ this ->bind ($ rule );
287+ if ($ this ->rule instanceof Closure) {
288+ Container::getInstance ()->invokeFunction ($ this ->rule );
290289 } elseif ($ this ->sub ) {
291290 $ this ->loadRoutes ($ this ->sub );
292291 }
0 commit comments