* Get module name by preg_match.

This commit is contained in:
Guan Xiying
2022-10-20 14:24:30 +08:00
parent 5498c0872b
commit a769caa8c5
+21 -5
View File
@@ -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);
}