@@ -234,32 +234,29 @@ public function create($name,
234
234
* @throws \Exception
235
235
* @return array
236
236
*/
237
- public function findMatchingRoute (string $ url ): array {
238
- if (substr ($ url , 0 , 6 ) === ' /apps/ ' ) {
237
+ public function findMatchingRoute (string $ url, bool $ loadAll = false ): array {
238
+ if (strpos ($ url , ' /apps/ ' ) === 0 ) {
239
239
// empty string / 'apps' / $app / rest of the route
240
240
[, , $ app ,] = explode ('/ ' , $ url , 4 );
241
241
242
242
$ app = \OC_App::cleanAppId ($ app );
243
243
\OC ::$ REQUESTEDAPP = $ app ;
244
244
$ this ->loadRoutes ($ app );
245
- } elseif (substr ($ url , 0 , 13 ) === '/ocsapp/apps/ ' ) {
245
+ } elseif (strpos ($ url , '/ocsapp/apps/ ' ) === 0 ) {
246
246
// empty string / 'ocsapp' / 'apps' / $app / rest of the route
247
247
[, , , $ app ,] = explode ('/ ' , $ url , 5 );
248
248
249
249
$ app = \OC_App::cleanAppId ($ app );
250
250
\OC ::$ REQUESTEDAPP = $ app ;
251
251
$ this ->loadRoutes ($ app );
252
- } elseif (substr ($ url , 0 , 10 ) === ' /settings/ ' ) {
252
+ } elseif (strpos ($ url , ' /settings/ ' ) === 0 ) {
253
253
$ this ->loadRoutes ('settings ' );
254
- } elseif (substr ($ url , 0 , 6 ) === '/core/ ' ) {
255
- \OC ::$ REQUESTEDAPP = $ url ;
256
- if (!\OC ::$ server ->getConfig ()->getSystemValueBool ('maintenance ' ) && !Util::needUpgrade ()) {
257
- \OC_App::loadApps ();
258
- }
259
- $ this ->loadRoutes ('core ' );
260
- } else {
261
- $ this ->loadRoutes ();
262
254
}
255
+ \OC ::$ REQUESTEDAPP = $ url ;
256
+ if (!\OC ::$ server ->getConfig ()->getSystemValueBool ('maintenance ' ) && !Util::needUpgrade ()) {
257
+ \OC_App::loadApps ();
258
+ }
259
+ $ this ->loadRoutes ('core ' );
263
260
264
261
$ matcher = new UrlMatcher ($ this ->root , $ this ->context );
265
262
try {
@@ -272,6 +269,11 @@ public function findMatchingRoute(string $url): array {
272
269
try {
273
270
$ parameters = $ matcher ->match ($ url . '/ ' );
274
271
} catch (ResourceNotFoundException $ newException ) {
272
+ // Attempt to fallback to load all routes if none of the above route patterns matches and the route is not in core
273
+ if (!$ loadAll ) {
274
+ $ this ->loadRoutes ();
275
+ return $ this ->findMatchingRoute ($ url , true );
276
+ }
275
277
// If we still didn't match a route, we throw the original exception
276
278
throw $ e ;
277
279
}
0 commit comments