mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-28 23:03:25 +09:00
Allow standalone routes from other modules to be used
This commit is contained in:
parent
2feba015f4
commit
bb3d1f08a1
3 changed files with 73 additions and 9 deletions
|
|
@ -136,6 +136,18 @@ class Router
|
|||
}
|
||||
}
|
||||
|
||||
// Check other modules.
|
||||
$all_routes = self::_getAllCachedRoutes();
|
||||
foreach ($all_routes->{$method} as $regexp => $action)
|
||||
{
|
||||
if (preg_match($regexp, $internal_url, $matches))
|
||||
{
|
||||
$matches = array_filter($matches, 'is_string', \ARRAY_FILTER_USE_KEY);
|
||||
$allargs = array_merge(['mid' => $prefix, 'act' => $action[1]], $matches, $args);
|
||||
return $allargs;
|
||||
}
|
||||
}
|
||||
|
||||
// Try the generic mid/act pattern.
|
||||
if (preg_match('#^[a-zA-Z0-9_]+$#', $internal_url))
|
||||
{
|
||||
|
|
@ -223,6 +235,18 @@ class Router
|
|||
}
|
||||
}
|
||||
|
||||
// Check other modules for $act.
|
||||
$all_routes = self::_getAllCachedRoutes();
|
||||
if (isset($all_routes->reverse[$act]))
|
||||
{
|
||||
$result = self::_getBestMatchingRoute($all_routes->reverse[$act], $args2);
|
||||
if ($result !== false)
|
||||
{
|
||||
self::$_route_cache[$keys_string] = '$mid/' . $result . '$act:delete';
|
||||
return $args['mid'] . '/' . self::_insertRouteVars($result, $args2);
|
||||
}
|
||||
}
|
||||
|
||||
// Check XE-compatible routes that start with $mid and contain no $act.
|
||||
if (!isset($args['act']) || ($args['act'] === 'rss' || $args['act'] === 'atom' || $args['act'] === 'api'))
|
||||
{
|
||||
|
|
@ -300,6 +324,23 @@ class Router
|
|||
return self::$_action_cache_module[$module] = $action_info ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of all cached routes from all modules.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected static function _getAllCachedRoutes()
|
||||
{
|
||||
$cache_key = 'site_and_module:action_with_routes';
|
||||
$result = Cache::get($cache_key);
|
||||
if ($result === null)
|
||||
{
|
||||
$result = (object)array('GET' => [], 'POST' => [], 'reverse' => []);
|
||||
Cache::set($cache_key, $result, 0, true);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the best matching route for an array of variables.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue