mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Add regexp to config for custom namespaces
This commit is contained in:
parent
4d4d454af0
commit
4f9f641067
2 changed files with 28 additions and 2 deletions
|
|
@ -1457,20 +1457,38 @@ class ModuleController extends Module
|
|||
{
|
||||
if(!isset($namespaces[$name]))
|
||||
{
|
||||
$namespaces[$name] = $module_name;
|
||||
$namespaces[$name] = 'modules/' . $module_name;
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove namespaces that are no longer defined by this module.
|
||||
foreach ($namespaces as $name => $attached_module)
|
||||
foreach ($namespaces as $name => $path)
|
||||
{
|
||||
$attached_module = preg_replace('!^modules/!', '', $path);
|
||||
if ($attached_module === $module_name && !in_array($name, $module_action_info->namespaces ?? []))
|
||||
{
|
||||
unset($namespaces[$name]);
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a regular expression for routing.
|
||||
$regexp = [];
|
||||
unset($namespaces['regexp']);
|
||||
foreach ($namespaces as $name => $path)
|
||||
{
|
||||
$regexp[] = preg_quote(strtr($name, '\\', '/'), '!');
|
||||
}
|
||||
if (count($regexp))
|
||||
{
|
||||
$namespaces['regexp'] = '!^(' . implode('|', $regexp) . ')/(\\w+/)*(\\w+)$!';
|
||||
}
|
||||
else
|
||||
{
|
||||
$namespaces['regexp'] = '';
|
||||
}
|
||||
|
||||
// Update system configuration.
|
||||
if ($changed)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1673,6 +1673,14 @@ class ModuleModel extends Module
|
|||
$info->need_update = true;
|
||||
}
|
||||
}
|
||||
foreach ($namespaces as $name => $path)
|
||||
{
|
||||
$attached_module = preg_replace('!^modules/!', '', $path);
|
||||
if ($attached_module === $module_name && !in_array($name, $module_action_info->namespaces ?? []))
|
||||
{
|
||||
$info->need_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all prefixes are registered.
|
||||
foreach ($module_action_info->prefixes ?? [] as $name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue