Library / SDK
doctrine-extensions/DoctrineExtensions avatar
doctrine-extensions/DoctrineExtensions

Doctrine Extensions 3.22: Behavioral Plugins for Doctrine ORM and MongoDB ODM

Doctrine2 behavioral extensions, Translatable, Sluggable, Tree-NestedSet, Timestampable, Loggable, Sortable.

4,138 stars1,250 forksPHPMIT

At a glance

What is it?
A review of the doctrine-extensions/DoctrineExtensions package, covering its suite of behavioral extensions, how they integrate with Doctrine's event system, and what to verify before adopting it in PHP projects.
Who is it for?
Adopt this package if you use Doctrine ORM or MongoDB ODM and need ready-made behaviors like Translatable, Sluggable, or Tree without writing your own event listeners. Avoid it if you require Loggable with DBAL 4, since that combination is not supported.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 15 days ago.
What is it written in?
Mainly PHP, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What This Package Solves for Doctrine Users

Doctrine ORM and MongoDB ODM give you persistence, but they do not handle common cross-cutting concerns like slugs, timestamps, translations, or tree structures. This package fills that gap by attaching behaviors to Doctrine's event system. It is for PHP developers who use Doctrine and want to add these features through metadata mapping rather than writing custom event listeners for every entity. The README lists extensions for both ORM and MongoDB ODM: Blameable, Loggable, Sluggable, Timestampable, Translatable, and Tree. ORM-only extensions include IpTraceable, SoftDeleteable, Sortable, and Uploadable. MongoDB ODM gets References and ReferenceIntegrity. If you have ever hand-rolled a slug generator or a created_at field, this package promises to replace that boilerplate with a declarative approach.

How the Extensions Hook Into Doctrine's Event System

The core mechanism is described as attaching to the event system and handling records being flushed in a behavioral way. Each extension listens to lifecycle events such as prePersist or preUpdate, and modifies the entity or document accordingly. For example, Timestampable updates date fields on create, update, or property change. Sluggable urlizes specified fields into a single unique slug. Translatable stores translations for records in different languages. Tree automates tree handling and adds tree-specific repository functions, supporting closure, nested set, or materialized path strategies, with MongoDB ODM limited to materialized path. The documentation gives a concrete example: the console command app:print-category-translation-tree prints a category translation tree, showing how the extensions work together. The event-driven design means you do not call these behaviors explicitly; they react to flushes, which keeps your domain code clean but also means you need to understand Doctrine's event lifecycle to debug issues.

Installation and Mapping Drivers

You install the package with Composer: composer require gedmo/doctrine-extensions. The README links to framework-specific docs for Symfony, Laravel, and Laminas, so integration is not one-size-fits-all. For mapping, all extensions support Attribute, XML, and Annotation, with Annotation deprecated. XML mapping requires a specific namespace: http://gediminasm.org/schemas/orm/doctrine-extensions-mapping. The root node must declare both the Doctrine mapping namespace and the gedmo namespace, as shown in the README's XML example. There are versioned XSD schemas, so you can pin to a specific version like 2.2.x. If you set up the Entity Manager without a framework, the README points to an example file, example/em.php, to prevent issues like #1310. This suggests that manual setup has pitfalls, so check that example before writing your own bootstrap.

Version Compatibility Constraints

The package has strict version requirements that you must check before adopting. For DBAL, it requires ^3.2 or ^4.0, but Loggable does not support DBAL 4. That means if you are on DBAL 4 and need Loggable, this package is not a fit. ORM versions supported are ^2.14 or ^3.0, and MongoDB ODM requires ^2.3. These are not loose constraints; they reflect the package's dependency on specific Doctrine APIs. The 3.0 release notes say it bumps minimum PHP and Doctrine versions and adds support for the latest MongoDB and Common packages. If you are on an older Doctrine setup, you will need to upgrade first. The README also warns about setting up the Entity Manager without a framework, so version mismatches can surface there. Before you commit, run composer require and let Composer resolve the dependencies to see if your project's versions align.

Running Tests and the Example

The project provides a Docker-based test setup. You run docker compose up -d, then docker compose exec php bash, then composer install, and finally vendor/bin/phpunit. This is useful for verifying the package works in your environment, but it requires Docker and a PHP container. For a quick demonstration, you can run the example: after composer install, edit example/em.php to configure your database, then run php example/bin/console orm:schema-tool:create to create the schema, and php example/bin/console app:print-category-translation-tree to print a category translation tree. This example is the fastest way to see how Translatable and Tree behave together. The README does not describe the output, so you will need to run it yourself to judge whether the behavior matches your expectations.

Limitations and Failure Modes

The most obvious limitation is the Loggable and DBAL 4 incompatibility. If your project uses DBAL 4, you cannot use Loggable, which is a significant gap for audit-trail needs. Another limitation is that MongoDB ODM only supports the materialized path strategy for Tree, so if you are on MongoDB and want nested set or closure, you are out of luck. The package also has a large surface area: twelve extensions, each with its own configuration. That means more documentation to read and more places for subtle bugs. The README mentions that annotations are deprecated, so if you have existing annotation mappings, you need to migrate to attributes or XML, which is a maintenance cost. Also, because behaviors are triggered by Doctrine events, they only fire when you flush through the Entity Manager. If you use raw SQL or bulk operations, the extensions will not apply, which can be a silent failure. The README does not discuss performance, but event listeners add overhead on every flush, so high-volume write workloads might see a slowdown.

Alternatives and How They Differ

A common alternative is to write your own event listeners or use a library like KnpLabs/DoctrineBehaviors. That package also provides Timestampable, Sluggable, Translatable, and Tree, but it uses PHP traits and events differently. DoctrineBehaviors tends to be lighter and more focused on a few behaviors, while this package offers a wider range, including Loggable, Sortable, and Uploadable. The key difference is that DoctrineExtensions supports multiple mapping drivers (attributes, XML, annotation) and has a longer history with the gedmo namespace. DoctrineBehaviors may be simpler to integrate because it relies on traits you add to your entities, whereas this package uses metadata mapping, which can be more flexible but also more complex. If you only need one or two behaviors, a custom listener might be simpler than adopting a full package. The choice depends on how many behaviors you need and how comfortable you are with event-driven configuration.

Maintenance and Upgrade Cost

The repository is active, with the latest release v3.22.1 pushed on 2026-08-01, and prior releases in 2025. This suggests ongoing maintenance, but the upgrade from 2.4.x to 3.0 is a major step. The README links to an upgrade doc, which implies breaking changes. You should read that document before upgrading. The package is MIT licensed, so you can modify it, but you are responsible for maintaining any forks. The test suite requires Docker, which is a barrier for some teams, but it also means the project has a reproducible test environment. The package has coding standards and QA workflows, which is a positive sign for code quality, but you cannot infer reliability from that alone. The main cost is learning the event system and mapping configurations for each extension. Plan time for debugging when a behavior does not trigger, especially if you are using XML mapping with the custom namespace.

Editorial conclusion

Adopt this package if you use Doctrine ORM or MongoDB ODM and need ready-made behaviors like Translatable, Sluggable, or Tree without writing your own event listeners. Avoid it if you require Loggable with DBAL 4, since that combination is not supported. Before integrating, verify your PHP and Doctrine versions meet the minimums, and check the upgrade guide if you are moving from 2.4.x. Also confirm your mapping driver: attributes and XML are supported, but annotations are deprecated, so plan to migrate if you rely on them. The package is actively maintained with recent releases, and the MIT license means you can adapt it, but the real cost is learning the event system integration and debugging when behaviors do not fire as expected. Start with the example script to see how the extensions behave in a minimal setup.

Official sources

  1. Official README
  2. Project repository
  3. Release notes
Community notes

Community notes