Skip to content

Commit

Permalink
模型实例化支持传入任意实体对象
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Apr 20, 2023
1 parent 5535503 commit af55970
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Model.php
Expand Up @@ -231,9 +231,9 @@ public function invoke($method, array $vars = [])
/**
* 架构函数.
*
* @param array|Model $data 数据
* @param array|object $data 数据
*/
public function __construct(array|Model $data = [])
public function __construct(array|object $data = [])
{
// 设置数据
$this->data($data);
Expand Down
6 changes: 4 additions & 2 deletions src/model/concern/Attribute.php
Expand Up @@ -221,16 +221,18 @@ protected function getRealFieldName(string $name): string
/**
* 设置数据对象值
*
* @param array|Model $data 数据
* @param array|object $data 数据
* @param bool $set 是否调用修改器
* @param array $allow 允许的字段名
*
* @return $this
*/
public function data(array|Model $data, bool $set = false, array $allow = [])
public function data(array|object $data, bool $set = false, array $allow = [])
{
if ($data instanceof Model) {
$data = $data->getData();
} elseif (is_object($data)) {
$data = get_object_vars($data);
}

// 清空数据
Expand Down

0 comments on commit af55970

Please sign in to comment.