PHPackages                             rulerz-php/doctrine-orm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. rulerz-php/doctrine-orm

ActiveLibrary[Database &amp; ORM](/categories/database)

rulerz-php/doctrine-orm
=======================

Doctrine ORM compilation target for RulerZ

360.1k↓46.4%2[2 issues](https://github.com/rulerz-php/doctrine-orm/issues)PHPCI failing

Since Jan 3Pushed 6y ago2 watchersCompare

[ Source](https://github.com/rulerz-php/doctrine-orm)[ Packagist](https://packagist.org/packages/rulerz-php/doctrine-orm)[ RSS](/packages/rulerz-php-doctrine-orm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Doctrine ORM compilation target for RulerZ [![Build Status](https://camo.githubusercontent.com/71c8fcc82146e463cbde924c11421ba2776771c475913f197c9b373661a0ed55/68747470733a2f2f7472617669732d63692e6f72672f72756c65727a2d7068702f646f637472696e652d6f726d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rulerz-php/doctrine-orm)
===============================================================================================================================================================================================================================================================================================================================================

[](#doctrine-orm-compilation-target-for-rulerz-)

Doctrine ORM compilation target for [RulerZ](https://github.com/K-Phoen/rulerz).

Usage
-----

[](#usage)

[Doctrine ORM](http://www.doctrine-project.org/projects/orm.html) is one of the targets supported by RulerZ.

This cookbook will show you how to retrieve objects using Doctrine and RulerZ.

Here is a summary of what you will have to do:

- [configure Doctrine ORM](#configure-doctrine-orm);
- [configure RulerZ](#configure-rulerz);
- [filter your target](#filter-your-target).

Configure Doctrine ORM
----------------------

[](#configure-doctrine-orm)

This subject won't be directly treated here. You can either follow the [official documentation](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html)or use a bundle/module/whatever the framework you're using promotes.

Configure RulerZ
----------------

[](#configure-rulerz)

Once Doctrine is installed and configured we can the RulerZ engine:

```
$rulerz = new RulerZ(
    $compiler, [
        new \RulerZ\DoctrineORM\Target\DoctrineORM(), // this line is Doctrine-specific
        // other compilation targets...
    ]
);
```

The only Doctrine-related configuration is the `DoctrineQueryBuilder` target being added to the list of the known compilation targets.

Filter your target
------------------

[](#filter-your-target)

Now that both Doctrine and RulerZ are ready, you can use them to retrieve data.

The `DoctrineQueryBuilder` instance that we previously injected into the RulerZ engine only knows how to use `QueryBuilder`s so the first step is to create one:

```
$playersQueryBuilder = $entityManager
    ->createQueryBuilder()
    ->select('p')
    ->from(Entity\Player::class, 'p');
```

And as usual, we call RulerZ with our target (the `QueryBuilder` object) and our rule. RulerZ will build the right executor for the given target and use it to filter the data, or in our case to retrieve data from a database.

```
$rule  = 'gender = :gender and points > :points';
$parameters = [
    'points' => 30,
    'gender' => 'M',
];

var_dump($rulerz->filter($playersQueryBuilder, $rule, $parameters));
```

Handling joins
--------------

[](#handling-joins)

More often that not, your entities will have relationships with other entities in your application.

Let's imagine that our `Entity\Player` entity has a 1-1 association with a `Entity\Group` entity and that we want to retrieve all the players that are in a group having the role *ROLE\_ADMIN*.

There are two ways to write rules using that association. In the first one, we let RulerZ automatically determine how to join the entities:

```
$playersQueryBuilder = $entityManager
    ->createQueryBuilder()
    ->select('p')
    ->from(Entity\Player::class, 'p');

$rule = '"ROLE_ADMIN" IN group.roles';

var_dump(
    iterator_to_array($rulerz->filter($playersQueryBuilder, $rule))
);
```

It's important to notice that `group` is not an ordinary attribute: it's another entity, joined by RulerZ.

**N.B:** RulerZ will call the `join()` method on the query builder, so it will perform INNER joins by default.

If you need more control on how the joins are handled, we can prepare the query builder and join the entities you need ourselves:

```
$playersQueryBuilder = $entityManager
    ->createQueryBuilder()
    ->select('p')
    ->from('Entity\Player', 'p')
    ->innerJoin('Entity\Group', 'g');

$rule = '"ROLE_ADMIN" IN g.roles';

var_dump(
    iterator_to_array($rulerz->filter($playersQueryBuilder, $rule))
);
```

This time, RulerZ is smart enough to understand that `g` might be a joined entity and that it should not try to join it itself.

License
-------

[](#license)

This library is under the [MIT](LICENSE) license.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance7

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/66958?v=4)[Kévin Gomez](/maintainers/K-Phoen)[@K-Phoen](https://github.com/K-Phoen)

---

Top Contributors

[![K-Phoen](https://avatars.githubusercontent.com/u/66958?v=4)](https://github.com/K-Phoen "K-Phoen (12 commits)")

### Embed Badge

![Health badge](/badges/rulerz-php-doctrine-orm/health.svg)

```
[![Health](https://phpackages.com/badges/rulerz-php-doctrine-orm/health.svg)](https://phpackages.com/packages/rulerz-php-doctrine-orm)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
