Optimize order of conditions in autoloader

This commit is contained in:
Kijin Sung 2023-08-12 01:18:59 +09:00
parent cd0779862e
commit 5823253d60

View file

@ -120,18 +120,6 @@ spl_autoload_register(function($class_name)
$lang_path = RX_BASEDIR . strtolower($matches[1]) . '/' . $lang_plugin . '/lang';
}
}
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]))
{
$lang_plugin = array_last(explode('/', $plugin_path));
$lang_path = RX_BASEDIR . $plugin_path . '/lang';
}
}
elseif (isset($GLOBALS['RX_AUTOLOAD_FILE_MAP'][$lc_class_name = strtolower($class_name)]))
{
$filename1 = RX_BASEDIR . $GLOBALS['RX_AUTOLOAD_FILE_MAP'][$lc_class_name];
@ -148,6 +136,18 @@ spl_autoload_register(function($class_name)
$lang_path = RX_BASEDIR . 'modules/' . $module . '/lang';
}
}
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]))
{
$lang_plugin = array_last(explode('/', $plugin_path));
$lang_path = RX_BASEDIR . $plugin_path . '/lang';
}
}
// Load the PHP file.
if ($filename1 && file_exists($filename1))