增加模型初始化方法

This commit is contained in:
yunwuxin
2016-04-08 15:20:09 +08:00
parent b2a592f94d
commit ba3120eb0f

View File

@@ -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