evyex / doctrine-orm-extender
Extension for Doctrine ORM.
0.2.0
2026-02-26 19:49 UTC
Requires
- php: ^8.1
- doctrine/orm: ^2.10|^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.93
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
This package is auto-updated.
Last update: 2026-02-26 19:50:26 UTC
README
Extension library for Doctrine ORM that builds QueryBuilder/Query from a declarative ruleset.
What It Does
- Creates a
QueryBuilderfromRuleSetInterface - Applies supported Doctrine expressions (
where,orderBy,groupBy,join,select) - Binds parameters from the ruleset
- Returns either a ready
QueryBuilderor a finalQuery
Requirements
- PHP
^8.1 doctrine/orm^2.10|^3.0
Install
composer require evyex/doctrine-orm-extender
Example
Without ruleset object, query logic is usually assembled inline in repository/service methods. With this package, the same logic can be moved to a dedicated business ruleset class:
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Parameter; use Evyex\DoctrineOrmExtender\QueryFactory\RuleSetInterface; final class ClientGroupDogs implements RuleSetInterface { public function __construct(private int $clientGroupId) { } public function getEntityClass(): string { return Animal::class; } public function getRootAlias(): string { return 'a'; } public function getRules(): array { return [ new Expr\Join(Expr\Join::INNER_JOIN, 'a.client', 'c'), new Expr\Andx(['c.group = :clientGroupId']), new Expr\Andx(['a.type = :animalType']), ]; } public function getParameters(): ArrayCollection { return new ArrayCollection([ new Parameter('clientGroupId', $this->clientGroupId), new Parameter('animalType', 'dog'), ]); } }
Then usage becomes explicit and reusable:
$dogs = $queryFactory ->createQuery(new ClientGroupDogs(5)) ->getResult();