@@ -51,6 +51,20 @@ class Lumen implements Adapter
5151 */
5252 protected $ routes = [];
5353
54+ /**
55+ * Array of merged old routes and API routes.
56+ *
57+ * @var array
58+ */
59+ protected $ mergedRoutes = [];
60+
61+ /**
62+ * Routes already defined on the router.
63+ *
64+ * @var \Illuminate\Routing\RouteCollection
65+ */
66+ protected $ oldRoutes ;
67+
5468 /**
5569 * Indicates if the middleware has been removed from the application instance.
5670 *
@@ -92,7 +106,7 @@ public function dispatch(Request $request, $version)
92106
93107 $ this ->removeMiddlewareFromApp ();
94108
95- $ routeCollector = $ this ->routes [ $ version] ;
109+ $ routeCollector = $ this ->mergeOldRoutes ( $ version) ;
96110 $ dispatcher = call_user_func ($ this ->dispatcherResolver , $ routeCollector );
97111
98112 $ this ->app ->setDispatcher ($ dispatcher );
@@ -102,6 +116,28 @@ public function dispatch(Request $request, $version)
102116 return $ this ->app ->dispatch ($ request );
103117 }
104118
119+ /**
120+ * Merge the old application routes with the API routes.
121+ *
122+ * @param string $version
123+ *
124+ * @return array
125+ */
126+ protected function mergeOldRoutes ($ version )
127+ {
128+ if (! isset ($ this ->oldRoutes )) {
129+ $ this ->oldRoutes = $ this ->app ->router ->getRoutes ();
130+ }
131+ if (! isset ($ this ->mergedRoutes [$ version ])) {
132+ $ this ->mergedRoutes [$ version ] = $ this ->routes [$ version ];
133+ foreach ($ this ->oldRoutes as $ route ) {
134+ $ this ->mergedRoutes [$ version ]->addRoute ($ route ['method ' ], $ route ['uri ' ], $ route ['action ' ]);
135+ }
136+ }
137+
138+ return $ this ->mergedRoutes [$ version ];
139+ }
140+
105141 /**
106142 * Normalize the request URI so that Lumen can properly dispatch it.
107143 *
0 commit comments