@@ -76,6 +76,108 @@ abstract class AbstractRouter implements RouterInterface
7676 'controllerSuffix ' => '' , // eg: 'Controller'
7777 ];
7878
79+ /**
80+ * static Routes - no dynamic argument match
81+ * 整个路由 path 都是静态字符串 e.g. '/user/login'
82+ * @var array[]
83+ * [
84+ * '/user/login' => [
85+ * // METHOD => [...] // 这里 key 和 value里的 'methods' 是一样的
86+ * 'GET' => [
87+ * 'handler' => 'handler',
88+ * 'option' => [...],
89+ * ],
90+ * 'PUT' => [
91+ * 'handler' => 'handler',
92+ * 'option' => [...],
93+ * ],
94+ * ...
95+ * ],
96+ * ... ...
97+ * ]
98+ */
99+ protected $ staticRoutes = [];
100+
101+ /**
102+ * regular Routes - have dynamic arguments, but the first node is normal string.
103+ * 第一节是个静态字符串,称之为有规律的动态路由。按第一节的信息进行分组存储
104+ * e.g '/hello[/{name}]' '/user/{id}'
105+ * @var array[]
106+ * [
107+ * // 使用完整的第一节作为key进行分组
108+ * 'a' => [
109+ * [
110+ * 'start' => '/a/',
111+ * 'regex' => '/a/(\w+)',
112+ * 'methods' => 'GET,POST',
113+ * 'handler' => 'handler',
114+ * 'option' => [...],
115+ * ],
116+ * ...
117+ * ],
118+ * 'add' => [
119+ * [
120+ * 'start' => '/add/',
121+ * 'regex' => '/add/(\w+)',
122+ * 'methods' => 'GET',
123+ * 'handler' => 'handler',
124+ * 'option' => [...],
125+ * ],
126+ * ...
127+ * ],
128+ * 'blog' => [
129+ * [
130+ * 'start' => '/blog/post-',
131+ * 'regex' => '/blog/post-(\w+)',
132+ * 'methods' => 'GET',
133+ * 'handler' => 'handler',
134+ * 'option' => [...],
135+ * ],
136+ * ...
137+ * ],
138+ * ... ...
139+ * ]
140+ */
141+ protected $ regularRoutes = [];
142+
143+ /**
144+ * vague Routes - have dynamic arguments,but the first node is exists regex.
145+ * 第一节就包含了正则匹配,称之为无规律/模糊的动态路由
146+ * e.g '/{name}/profile' '/{some}/{some2}'
147+ * @var array
148+ * [
149+ * // 使用 HTTP METHOD 作为 key进行分组
150+ * 'GET' => [
151+ * [
152+ * // 必定包含的字符串
153+ * 'include' => '/profile',
154+ * 'regex' => '/(\w+)/profile',
155+ * 'handler' => 'handler',
156+ * 'option' => [...],
157+ * ],
158+ * ...
159+ * ],
160+ * 'POST' => [
161+ * [
162+ * 'include' => null,
163+ * 'regex' => '/(\w+)/(\w+)',
164+ * 'handler' => 'handler',
165+ * 'option' => [...],
166+ * ],
167+ * ...
168+ * ],
169+ * ... ...
170+ * ]
171+ */
172+ protected $ vagueRoutes = [];
173+
174+ /**
175+ * There are last route caches
176+ * @see $staticRoutes
177+ * @var array[]
178+ */
179+ protected $ routeCaches = [];
180+
79181 /**
80182 * object creator.
81183 * @param array $config
@@ -379,6 +481,13 @@ abstract protected function findInRegularRoutes(array $routesData, $path, $metho
379481 */
380482 abstract protected function findInVagueRoutes (array $ routesData , $ path , $ method );
381483
484+ /**
485+ * @param string $path
486+ * @param string $method
487+ * @param array $conf
488+ */
489+ abstract protected function cacheMatchedParamRoute ($ path , $ method , array $ conf );
490+
382491 /**
383492 * handle auto route match, when config `'autoRoute' => true`
384493 * @param string $path The route path
@@ -526,4 +635,60 @@ public static function getSupportedMethods()
526635 {
527636 return self ::SUPPORTED_METHODS ;
528637 }
638+
639+ /**
640+ * @param array $staticRoutes
641+ */
642+ public function setStaticRoutes (array $ staticRoutes )
643+ {
644+ $ this ->staticRoutes = $ staticRoutes ;
645+ }
646+
647+ /**
648+ * @return array
649+ */
650+ public function getStaticRoutes ()
651+ {
652+ return $ this ->staticRoutes ;
653+ }
654+
655+ /**
656+ * @param \array[] $regularRoutes
657+ */
658+ public function setRegularRoutes (array $ regularRoutes )
659+ {
660+ $ this ->regularRoutes = $ regularRoutes ;
661+ }
662+
663+ /**
664+ * @return \array[]
665+ */
666+ public function getRegularRoutes ()
667+ {
668+ return $ this ->regularRoutes ;
669+ }
670+
671+ /**
672+ * @param array $vagueRoutes
673+ */
674+ public function setVagueRoutes ($ vagueRoutes )
675+ {
676+ $ this ->vagueRoutes = $ vagueRoutes ;
677+ }
678+
679+ /**
680+ * @return array
681+ */
682+ public function getVagueRoutes ()
683+ {
684+ return $ this ->vagueRoutes ;
685+ }
686+
687+ /**
688+ * @return array
689+ */
690+ public function getRouteCaches ()
691+ {
692+ return $ this ->routeCaches ;
693+ }
529694}
0 commit comments