From 5823253d6056b92272ff329d311eb55e1b1212cc Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sat, 12 Aug 2023 01:18:59 +0900 Subject: [PATCH] Optimize order of conditions in autoloader --- common/autoload.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/common/autoload.php b/common/autoload.php index 136f936d5..86f878710 100644 --- a/common/autoload.php +++ b/common/autoload.php @@ -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))