geosocio / entity-utils
Doctrine 实体工具
1.2.2
2018-02-19 13:01 UTC
Requires (Dev)
- doctrine/collections: ^1.0
- doctrine/orm: ^2.0
- phpunit/phpunit: ^6.2
- squizlabs/php_codesniffer: ^3.0
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; }