mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-02 21:52:34 +08:00
增加模型初始化方法
This commit is contained in:
@@ -64,6 +64,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
// 是否为更新数据
|
||||
protected $isUpdate;
|
||||
|
||||
/**
|
||||
* 初始化过的模型.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $initialized = [];
|
||||
|
||||
/**
|
||||
* 架构函数
|
||||
* @access public
|
||||
@@ -77,6 +84,32 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$this->data = $data;
|
||||
}
|
||||
$this->name = basename(str_replace('\\', '/', get_class($this)));
|
||||
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化模型
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
$class = get_class($this);
|
||||
if (!isset(static::$initialized[$class])) {
|
||||
static::$initialized[$class] = true;
|
||||
static::init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化处理
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// JsonSerializable
|
||||
|
||||
Reference in New Issue
Block a user