mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-12 05:22:35 +09:00
Use associative array to store custom namespaces
This commit is contained in:
parent
911772393a
commit
a7954506f6
5 changed files with 22 additions and 22 deletions
|
|
@ -138,14 +138,17 @@ spl_autoload_register(function($class_name)
|
||||||
}
|
}
|
||||||
elseif (isset($GLOBALS['RX_NAMESPACES']) && preg_match($GLOBALS['RX_NAMESPACES']['regexp'], $class_name, $matches))
|
elseif (isset($GLOBALS['RX_NAMESPACES']) && preg_match($GLOBALS['RX_NAMESPACES']['regexp'], $class_name, $matches))
|
||||||
{
|
{
|
||||||
$plugin_path = $GLOBALS['RX_NAMESPACES'][strtr($matches[1], '/', '\\')] ?? '';
|
$plugin_path = $GLOBALS['RX_NAMESPACES']['mapping'][strtr($matches[1], '/', '\\')] ?? '';
|
||||||
$dir = RX_BASEDIR . $plugin_path . '/' . strtolower($matches[2]);
|
if ($plugin_path)
|
||||||
$filename1 = $dir . $matches[3] . '.php';
|
|
||||||
$filename2 = $dir . strtolower($matches[3]) . '.php';
|
|
||||||
if ($matches[1] !== 'Framework' && !empty($matches[3]))
|
|
||||||
{
|
{
|
||||||
$lang_plugin = array_last(explode('/', $plugin_path));
|
$dir = RX_BASEDIR . $plugin_path . '/' . strtolower($matches[2]);
|
||||||
$lang_path = RX_BASEDIR . $plugin_path . '/lang';
|
$filename1 = $dir . $matches[3] . '.php';
|
||||||
|
$filename2 = $dir . strtolower($matches[3]) . '.php';
|
||||||
|
if ($matches[1] !== 'Framework' && !empty($matches[3]))
|
||||||
|
{
|
||||||
|
$lang_plugin = array_last(explode('/', $plugin_path));
|
||||||
|
$lang_path = RX_BASEDIR . $plugin_path . '/lang';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,10 @@ return array(
|
||||||
'tablets' => false,
|
'tablets' => false,
|
||||||
'viewport' => 'width=device-width, initial-scale=1.0, user-scalable=yes',
|
'viewport' => 'width=device-width, initial-scale=1.0, user-scalable=yes',
|
||||||
),
|
),
|
||||||
'namespaces' => [],
|
'namespaces' => [
|
||||||
'prefixes' => [],
|
'mapping' => [],
|
||||||
|
'regexp' => '',
|
||||||
|
],
|
||||||
'use_rewrite' => true,
|
'use_rewrite' => true,
|
||||||
'use_sso' => false,
|
'use_sso' => false,
|
||||||
'other' => array(),
|
'other' => array(),
|
||||||
|
|
|
||||||
|
|
@ -42,16 +42,11 @@ class Config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty(self::$_config['namespaces']))
|
if (isset(self::$_config['namespaces']) && !empty(self::$_config['namespaces']['regexp']))
|
||||||
{
|
{
|
||||||
$GLOBALS['RX_NAMESPACES'] = self::$_config['namespaces'];
|
$GLOBALS['RX_NAMESPACES'] = self::$_config['namespaces'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty(self::$_config['prefixes']))
|
|
||||||
{
|
|
||||||
$GLOBALS['RX_PREFIXES'] = self::$_config['prefixes'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$_config;
|
return self::$_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1463,20 +1463,20 @@ class ModuleController extends Module
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($namespaces[$name]))
|
if (!isset($namespaces['mapping'][$name]))
|
||||||
{
|
{
|
||||||
$namespaces[$name] = 'modules/' . $module_name;
|
$namespaces['mapping'][$name] = 'modules/' . $module_name;
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove namespaces that are no longer defined by this module.
|
// Remove namespaces that are no longer defined by this module.
|
||||||
foreach ($namespaces as $name => $path)
|
foreach ($namespaces['mapping'] ?? [] as $name => $path)
|
||||||
{
|
{
|
||||||
$attached_module = preg_replace('!^modules/!', '', $path);
|
$attached_module = preg_replace('!^modules/!', '', $path);
|
||||||
if ($attached_module === $module_name && !in_array($name, $module_action_info->namespaces ?? []))
|
if ($attached_module === $module_name && !in_array($name, $module_action_info->namespaces ?? []))
|
||||||
{
|
{
|
||||||
unset($namespaces[$name]);
|
unset($namespaces['mapping'][$name]);
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1484,7 +1484,7 @@ class ModuleController extends Module
|
||||||
// Generate a regular expression for routing.
|
// Generate a regular expression for routing.
|
||||||
$regexp = [];
|
$regexp = [];
|
||||||
unset($namespaces['regexp']);
|
unset($namespaces['regexp']);
|
||||||
foreach ($namespaces as $name => $path)
|
foreach ($namespaces['mapping'] ?? [] as $name => $path)
|
||||||
{
|
{
|
||||||
$regexp[] = preg_quote(strtr($name, '\\', '/'), '!');
|
$regexp[] = preg_quote(strtr($name, '\\', '/'), '!');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1738,12 +1738,12 @@ class ModuleModel extends Module
|
||||||
$namespaces = config('namespaces') ?? [];
|
$namespaces = config('namespaces') ?? [];
|
||||||
foreach ($module_action_info->namespaces ?? [] as $name)
|
foreach ($module_action_info->namespaces ?? [] as $name)
|
||||||
{
|
{
|
||||||
if(!isset($namespaces[$name]))
|
if(!isset($namespaces['mapping'][$name]))
|
||||||
{
|
{
|
||||||
$info->need_update = true;
|
$info->need_update = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($namespaces as $name => $path)
|
foreach ($namespaces['mapping'] ?? [] as $name => $path)
|
||||||
{
|
{
|
||||||
$attached_module = preg_replace('!^modules/!', '', $path);
|
$attached_module = preg_replace('!^modules/!', '', $path);
|
||||||
if ($attached_module === $module_name && !in_array($name, $module_action_info->namespaces ?? []))
|
if ($attached_module === $module_name && !in_array($name, $module_action_info->namespaces ?? []))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue