Use associative array to store custom namespaces

This commit is contained in:
Kijin Sung 2023-08-12 21:53:52 +09:00
parent 911772393a
commit a7954506f6
5 changed files with 22 additions and 22 deletions

View file

@ -138,14 +138,17 @@ spl_autoload_register(function($class_name)
}
elseif (isset($GLOBALS['RX_NAMESPACES']) && preg_match($GLOBALS['RX_NAMESPACES']['regexp'], $class_name, $matches))
{
$plugin_path = $GLOBALS['RX_NAMESPACES'][strtr($matches[1], '/', '\\')] ?? '';
$dir = RX_BASEDIR . $plugin_path . '/' . strtolower($matches[2]);
$filename1 = $dir . $matches[3] . '.php';
$filename2 = $dir . strtolower($matches[3]) . '.php';
if ($matches[1] !== 'Framework' && !empty($matches[3]))
$plugin_path = $GLOBALS['RX_NAMESPACES']['mapping'][strtr($matches[1], '/', '\\')] ?? '';
if ($plugin_path)
{
$lang_plugin = array_last(explode('/', $plugin_path));
$lang_path = RX_BASEDIR . $plugin_path . '/lang';
$dir = RX_BASEDIR . $plugin_path . '/' . strtolower($matches[2]);
$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';
}
}
}

View file

@ -135,8 +135,10 @@ return array(
'tablets' => false,
'viewport' => 'width=device-width, initial-scale=1.0, user-scalable=yes',
),
'namespaces' => [],
'prefixes' => [],
'namespaces' => [
'mapping' => [],
'regexp' => '',
],
'use_rewrite' => true,
'use_sso' => false,
'other' => array(),

View file

@ -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'];
}
if (!empty(self::$_config['prefixes']))
{
$GLOBALS['RX_PREFIXES'] = self::$_config['prefixes'];
}
return self::$_config;
}