From a769caa8c57b7e5c4b4b246736f4089552116876 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 20 Oct 2022 14:24:30 +0800 Subject: [PATCH] * Get module name by preg_match. --- framework/model.class.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/framework/model.class.php b/framework/model.class.php index 062cf998c9..977e69c42b 100644 --- a/framework/model.class.php +++ b/framework/model.class.php @@ -367,12 +367,28 @@ class model extends baseModel public static function __callStatic($method, $arguments) { global $app; - $moduleName = get_called_class(); - $taoClass = 'ext' . $moduleName . 'Tao'; - if(is_callable("{$taoClass}::{$method}")) return call_user_func_array("{$taoClass}::{$method}", $arguments); - $taoClass = $moduleName . 'Tao'; - if(is_callable("{$taoClass}::{$method}")) return call_user_func_array("{$taoClass}::{$method}", $arguments); + $moduleName = strtolower(get_called_class()); + + preg_match_all('/^(ext)?(\w+)model/', $moduleName, $matches); + if(isset($matches[2][0])) + { + $moduleName = $matches[2][0]; + } + else + { + preg_match_all('/^(ext)?(\w+)tao/', $moduleName, $matches); + if(isset($matches[2][0])) $moduleName = $matches[2][0]; + } + + $modelClass = 'ext' . $moduleName . 'Model'; + if(method_exists($modelClass, $method)) return call_user_func_array("{$modelClass}::{$method}", $arguments); + + $taoClass = 'ext' . $moduleName . 'Tao'; + if(method_exists($taoClass, $method)) return call_user_func_array("{$taoClass}::{$method}", $arguments); + + $taoClass = $moduleName . 'Tao'; + if(method_exists($taoClass, $method)) return call_user_func_array("{$taoClass}::{$method}", $arguments); $app->triggerError("the module {$moduleName} has no {$method} method", __FILE__, __LINE__, $exit = true); }