File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -132,6 +132,27 @@ public function getAlias(): string
132132 return $ this ->alias ?: '' ;
133133 }
134134
135+ /**
136+ * 自动加载分组路由
137+ * @access protected
138+ * @return void
139+ */
140+ protected function loadRoutes (): void
141+ {
142+ // 加载路由定义
143+ $ routePath = root_path ('route ' . DIRECTORY_SEPARATOR . $ this ->fullName );
144+
145+ if (is_dir ($ routePath )) {
146+ $ origin = $ this ->router ->getGroup ();
147+ $ this ->router ->setGroup ($ this );
148+ $ files = glob ($ routePath . '*.php ' );
149+ foreach ($ files as $ file ) {
150+ include_once $ file ;
151+ }
152+ $ this ->router ->setGroup ($ origin );
153+ }
154+ }
155+
135156 /**
136157 * 检测分组路由
137158 * @access public
@@ -142,6 +163,14 @@ public function getAlias(): string
142163 */
143164 public function check (Request $ request , string $ url , bool $ completeMatch = false )
144165 {
166+ if ($ this ->fullName ) {
167+ $ groupName = str_replace ('/ ' , '| ' , $ this ->fullName );
168+ if ($ groupName == $ url || 0 === strpos ($ url , $ groupName . '| ' )){
169+ // 自动加载分组路由(子目录)
170+ $ this ->loadRoutes ();
171+ }
172+ }
173+
145174 // 检查分组有效性
146175 if (!$ this ->checkOption ($ this ->option , $ request ) || !$ this ->checkUrl ($ url )) {
147176 return false ;
You can’t perform that action at this time.
0 commit comments