From 2e76ce339faed0ee67e669186411ce8f0f229dc0 Mon Sep 17 00:00:00 2001 From: lilimin <461353919@qq.com> Date: Wed, 1 Oct 2025 07:26:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=85=E5=85=81=E8=AE=B8=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20Entity::=5F=5FcallStatic=20=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E6=A8=A1=E5=9E=8B=E7=9A=84=20public=20static?= =?UTF-8?q?=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8C=85=E6=8B=AC=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=9A=84=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E5=9B=BA=E5=AE=9A=E5=86=99?= =?UTF-8?q?=E6=AD=BB=E7=9A=84=E5=87=A0=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Entity.php b/src/Entity.php index a6005aab..3a8b8bc7 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -326,9 +326,14 @@ public function offsetUnset(mixed $name): void public static function __callStatic($method, $args) { $entity = new static(); - if (in_array($method, ['destroy', 'create', 'update', 'saveAll'])) { + $modelClass = get_class($entity->model()); + + $staticMethods = (new \ReflectionClass($modelClass))->getMethods(\ReflectionMethod::IS_STATIC); + $staticPublicMethods = array_filter($staticMethods, fn($m) => $m->isPublic()); + + if (in_array($method, array_column($staticPublicMethods, 'name'))) { // 调用model的静态方法 - $db = $entity->model(); + $db = $modelClass; } else { // 调用Query类查询方法 $db = $entity->model()->db();