From ba3120eb0fdd417fa670c3497ec33d801b765499 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Fri, 8 Apr 2016 15:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9E=8B=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/library/think/Model.php b/library/think/Model.php index f52fefeb..49819f4c 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -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