This commit is contained in:
2020-11-12 00:07:46 +08:00
parent 559ae6647e
commit 45d9e01445
2 changed files with 26 additions and 12 deletions
+12 -12
View File
@@ -24,9 +24,9 @@ abstract class HasBase
protected $data; protected $data;
/** /**
* @var string * @var IOrm
*/ */
protected string $model; protected IOrm $model;
/** @var */ /** @var */
protected $primaryId; protected $primaryId;
@@ -38,20 +38,20 @@ abstract class HasBase
/** @var Relation $_relation */ /** @var Relation $_relation */
protected Relation $_relation; protected Relation $_relation;
/** /**
* HasBase constructor. * HasBase constructor.
* @param $model * @param IOrm $model
* @param $primaryId * @param $primaryId
* @param $value * @param $value
* @param Relation $relation * @param Relation $relation
* @throws Exception * @throws Exception
*/ */
public function __construct($model, $primaryId, $value, Relation $relation) public function __construct(IOrm $model, $primaryId, $value, Relation $relation)
{ {
if (!class_exists($model)) { if (!class_exists($model)) {
throw new Exception('Model must implement ' . ActiveRecord::class); throw new Exception('Model must implement ' . ActiveRecord::class);
} }
if (!in_array(ActiveRecord::class, class_implements($model))) { if (!in_array(IOrm::class, class_implements($model))) {
throw new Exception('Model must implement ' . ActiveRecord::class); throw new Exception('Model must implement ' . ActiveRecord::class);
} }
if (is_array($value)) { if (is_array($value)) {
+14
View File
@@ -23,6 +23,20 @@ interface IOrm
*/ */
public static function findOne($param, $db = NULL); public static function findOne($param, $db = NULL);
/**
* @return string
*/
public static function className();
/**
* @return ActiveQuery
* return a sql queryBuilder
*/
public static function find();
/** /**
* @param $dbName * @param $dbName
* @return Connection * @return Connection