geosocio/entity-utils

Doctrine 实体工具

1.2.2 2018-02-19 13:01 UTC

This package is auto-updated.

Last update: 2024-09-12 00:39:34 UTC


README

提供简单的 Doctrine 实体工具。

参数包

通过构造函数轻松构建实体。

use GeoSocio\EntityUtils\ParameterBag;

class User {

  __construct(array $data = []) {
    $params = new ParameterBag($data);
    $this->id = $params->getInt('id');
    $this->first = $params->getString('first');
    $this->last = $params->getString('last');
    $this->address = $params->getInstance('address', Address::class, new Address());
    $this->posts = $params->getCollection('posts', Post::class, new ArrayCollection());
  }

}

创建Trait

将 trait 包含到实体中以添加一个在持久化时添加的 'created' 字段。

use GeoSocio\EntityUtils\CreatedTrait;

class User {

  use CreatedTrait;

}