infinite-networks/specifications
Composer 安装命令:
composer require infinite-networks/specifications
包简介
A specifications library for the Doctrine ORM
README 文档
README
This library is a base set of objects following the Specification pattern and based on a blog post about taming Doctrines EntityRepository classes.
http://www.whitewashing.de/2013/03/04/doctrine_repositories.html
How to use this library
This library adds 2 methods to the base EntityRepository class, match and matchOne,
which both accept a specification that will build a query builder. Developers need to
implement specifications that meet their domain requirements, and each specification must
implement the Infinite\Specification\ORM\Specification interface.
An example of what using this library could look like:
use Infinite\Specification\ORM as Spec; $repository = $managerRegistry->getRepository('Entity\User'); // Retrieve any enabled users, ordered by username $enabledUsersSpec = new Spec\Sort(array('username' => 'ASC'), new Spec\AndX(array( new Spec\Equals('enabled', 1) )); $enabledUsers = $repository->match($enabledUsersSpec); // Count enabled users $countEnabledUsersSpec = new Spec\SingleScalar(new Spec\Count(new Spec\Equals('enabled', 1))); $enabledUsersCount = $repository->matchOne($countEnabledUsersSpec);
Doctrine must be configured to use a different base EntityRepository class, and any EntityRepositories implemented in your application must use the EntityRepository class defined in this library as their base class.
To define a different EntityRepository base class in Symfony2, add the following configuration:
doctrine: orm: default_repository_class: Infinite\Specification\ORM\EntityRepository
统计信息
- 总下载量: 516
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-07-11