PHPackages                             vrok/doctrine-addons - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. vrok/doctrine-addons

ActiveLibrary[Testing &amp; Quality](/categories/testing)

vrok/doctrine-addons
====================

Doctrine ORM type &amp; helper classes

3.0.1(3mo ago)06.9k1MITPHPPHP ^8.4CI passing

Since Jul 3Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/j-schumann/doctrine-addons)[ Packagist](https://packagist.org/packages/vrok/doctrine-addons)[ Docs](https://vrok.de)[ RSS](/packages/vrok-doctrine-addons/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (33)Used By (1)

vrok/doctrine-addons
====================

[](#vrokdoctrine-addons)

This is a library with additional classes for usage in combination with the Doctrine ORM.

[![CI Status](https://github.com/j-schumann/doctrine-addons/actions/workflows/ci.yaml/badge.svg)](https://github.com/j-schumann/doctrine-addons/actions)[![Coverage Status](https://camo.githubusercontent.com/fc523c11ed8e2435e3e4bba0f2f81cdea04d49a65d50afba05fcf6f577e8d24f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a2d736368756d616e6e2f646f637472696e652d6164646f6e732f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/j-schumann/doctrine-addons?branch=main)

Enable Postgres specific DQL functions
--------------------------------------

[](#enable-postgres-specific-dql-functions)

`CAST` implements the corresponding function from Postgres to convert types:

```
$queryBuilder->expr()->like('CAST(u.varchar, \'text\'))', ':parameterName')
```

`CONTAINS` allows to use the [postgres-only "@&gt;" operator](https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-JSONB-OP-TABLE)to search for values within jsonb fields or arrays.

```
$qb->andWhere("CONTAINS(u.numbers, :number) = true")
   ->setParameter('number', 3);
```

`JSON_CONTAINS_TEXT` allows to use the [postgres-only "?" operator](https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-JSONB-OP-TABLE)to search for strings within jsonb fields. This for example allows to filter Symfony users correctly by role, e.g. if you use role names that are part of others (ROLE\_SUPER &amp; ROLE\_SUPER\_ADMIN) where using `LIKE` would fail.

```
$qb->andWhere("JSON_CONTAINS_TEXT(u.roles, :searchRole) = true")
   ->setParameter('searchRole', 'ROLE_ADMIN');
```

`JSON_FIELD_AS_TEXT` allows to use the [postgres-only "-&gt;&gt;" operator](https://www.postgresql.org/docs/9.5/functions-json.html#FUNCTIONS-JSON)to get JSON data within a jsonb fields as string. This for example allows to search for records that embed JSON, e.g. if you store metadata or addresses:

```
$qb->andWhere("JSON_FIELD_AS_TEXT('u.address, :addrField) = :addrValue")
    ->setParameter('addrField', 'city')
    ->setParameter('addrValue', 'Dresden');
```

Add to config/packages/doctrine.yaml:

```
doctrine:
    orm:
        dql:
            string_functions:
                CAST: Vrok\DoctrineAddons\ORM\Query\AST\CastFunction
                CONTAINS: Vrok\DoctrineAddons\ORM\Query\AST\ContainsFunction
                JSON_CONTAINS_TEXT: Vrok\DoctrineAddons\ORM\Query\AST\JsonContainsTextFunction
                JSON_FIELD_AS_TEXT: Vrok\DoctrineAddons\ORM\Query\AST\JsonFieldAsTextFunction
```

Enable types in Symfony
-----------------------

[](#enable-types-in-symfony)

config/packages/doctrine.yaml

```
doctrine:
    dbal:
        types:
            # force all dates/times to be stored in UTC
            utcdatetime:
                name: datetime_immutable
                class: Vrok\DoctrineAddons\DBAL\Types\UTCDateTimeType

            # MariaDB does not support the JSON type, so we do not benefit from
            # validation/searching/path syntax etc. Also it uses a LONGTEXT
            # instead, which has a performance hit because it is stored outside
            # the row and causes possible temp tables to be written to disk
            smalljson:
                name: small_json
                class: Vrok\DoctrineAddons\DBAL\Types\SmallJsonType
```

Enable the MariadbTestDriver in Symfony
---------------------------------------

[](#enable-the-mariadbtestdriver-in-symfony)

config/packages/test/doctrine.yaml

```
doctrine:
    dbal:
        # There is a bug in Doctrine\Common\DataFixtures\Purger\ORMPurger
        # which causes tables that are target of a foreign key constraint to
        # be deleted before the association table(s), which in turn causes
        # "1701 Cannot truncate a table referenced in a foreign key constraint"
        # So we use our custom driver to disable foreign key checks for TRUNCATE
        # because only with TRUNCATE instead of DELETE FROM we ensure the same
        # autoincrement IDs for fixtures in tests
        # "driver" left blank intentionally
        driver:
        driver_class: Vrok\DoctrineAddons\DAL\Driver\MariadbTestDriver
```

Enable the PostgreSQLTestDriver in Symfony
------------------------------------------

[](#enable-the-postgresqltestdriver-in-symfony)

config/packages/test/doctrine.yaml

```
doctrine:
    dbal:
        # Default purge/TRUNCATE behavior of Postgres does not reset autoincrement
        # values, so we use our custom driver to reset identities for TRUNCATE.
        # "driver" left blank intentionally
        driver:
        driver_class: Vrok\DoctrineAddons\DAL\Driver\PostgreSQLTestDriver
```

Lockable entities
-----------------

[](#lockable-entities)

Implementing a simple `LockableInterface` allows unified handling of different entities that can be locked/unlocked by admins etc. The provided interface makes very little assumptions about your code, except that each entity can be locked/unlocked at any time (regardless of other states the entity might have).

The `LockableTrait` provides an opinionated implementation of that interface, by specifying a boolean property `locked` that defaults to false and that has a Symfony group attribute of `default:read`.

Slugs with correct umlauts in Symfony
-------------------------------------

[](#slugs-with-correct-umlauts-in-symfony)

Add this to your services.yaml to have ae, ue, oe in your slugs instead of a, u, o for ä, ü, ö.
This also handles some other chars, e.g. accents.
Requires `symfony/translation-contracts`.

```
    gedmo.listener.sluggable:
      class: Gedmo\Sluggable\SluggableListener
      tags:
        - { name: doctrine.event_listener, event: 'prePersist' }
        - { name: doctrine.event_listener, event: 'onFlush' }
        - { name: doctrine.event_listener, event: 'loadClassMetadata' }
      calls:
        - [ setTransliterator, [ [ 'Vrok\DoctrineAddons\Util\UmlautTransliterator', 'transliterate' ] ] ]
```

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance86

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.7% 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.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~118 days

Total

30

Last Release

97d ago

Major Versions

v1.2.2 → v2.0.02022-01-10

2.15.0 → 3.0.02025-12-02

PHP version history (6 changes)v1.0.0PHP ^7.4

v1.2.1PHP ^7.4|^8.0

v2.4.0PHP ^8.1

2.13.0PHP ^8.2

2.15.0PHP ^8.3

3.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed9373b6806c33f512ca3b63214dd2a2b2621bcbddffcdb99acc66ae7f0324aa?d=identicon)[j-schumann](/maintainers/j-schumann)

---

Top Contributors

[![j-schumann](https://avatars.githubusercontent.com/u/114239?v=4)](https://github.com/j-schumann "j-schumann (132 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (4 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (2 commits)")

---

Tags

phpunittesttypeormdoctrinenormalizationutc

###  Code Quality

TestsPHPUnit

Static AnalysisRector

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/vrok-doctrine-addons/health.svg)

```
[![Health](https://phpackages.com/badges/vrok-doctrine-addons/health.svg)](https://phpackages.com/packages/vrok-doctrine-addons)
```

###  Alternatives

[zenstruck/foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.

78311.9M97](/packages/zenstruck-foundry)[lchrusciel/api-test-case

Perfect PHPUnit TestCase for JSON/XML API TDD with Symfony.

4115.5M63](/packages/lchrusciel-api-test-case)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[kenjis/ci-phpunit-test

An easier way to use PHPUnit with CodeIgniter 3.x

5861.2M3](/packages/kenjis-ci-phpunit-test)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M397](/packages/php-mock-php-mock-phpunit)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)

PHPackages © 2026

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