From f814fc32ba5529744a02f5f7f1d5f2ee37c3d6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 10 Nov 2020 11:36:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ActiveRecord.php | 1 + Database/HasBase.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Database/ActiveRecord.php b/Database/ActiveRecord.php index 9759801f..62c1d108 100644 --- a/Database/ActiveRecord.php +++ b/Database/ActiveRecord.php @@ -6,6 +6,7 @@ * Time: 14:39 */ declare(strict_types=1); + namespace Database; diff --git a/Database/HasBase.php b/Database/HasBase.php index ef6834a5..80a6ac7d 100644 --- a/Database/HasBase.php +++ b/Database/HasBase.php @@ -24,7 +24,7 @@ abstract class HasBase protected $data; /** - * @var string + * @var string */ protected string $model; @@ -48,6 +48,12 @@ abstract class HasBase */ public function __construct($model, $primaryId, $value, Relation $relation) { + if (!class_exists($model)) { + throw new Exception('Model must implement ' . ActiveRecord::class); + } + if (!in_array(ActiveRecord::class, class_implements($model))) { + throw new Exception('Model must implement ' . ActiveRecord::class); + } if (is_array($value)) { if (empty($value)) $value = []; $_model = $model::find()->in($primaryId, $value);