DoctrineBundle
Symfony bundle that wires Doctrine ORM and DBAL into your application
Repository Health
Technical Analysis
DoctrineBundle is the official integration layer between the Doctrine ORM/DBAL persistence libraries and the Symfony framework. Rather than requiring you to manually construct an EntityManager, connection factory, and metadata driver chain, the bundle registers all of it as Symfony services through a dependency-injection extension, reads database and ORM configuration from config/packages/doctrine.yaml, and exposes a set of console commands (doctrine:database:create, doctrine:schema:update, doctrine:migrations:* via companion bundles, etc.) for day-to-day database operations.
Beyond basic wiring, it adds Symfony-specific conveniences on top of vanilla Doctrine: attribute-based entity listeners and middleware registration, a ServiceEntityRepository base class that autowires the entity manager, a data collector for the Symfony profiler toolbar showing query counts and timings, cache warmers for metadata/proxy classes, and compiler passes that let other bundles hook into repository and ID-generator registration. It supports multiple connections and entity managers in a single application, making it the standard way any Symfony project talks to a relational database.
What You Get
- A
DependencyInjectionextension that buildsEntityManager,Connection, and metadata-driver services fromdoctrine.yamlconfiguration, supporting multiple connections/entity managers per application - Console commands for schema and database management (
doctrine:database:create/drop,doctrine:schema:update/validate, cache clearing) registered automatically in the Symfony console ServiceEntityRepository— a base repository class that autowires the correct entity manager, removing the boilerplate of manually injectingEntityManagerInterfaceinto every repository- Attribute-driven configuration:
#[AsEntityListener],#[AsDoctrineListener], and#[AsMiddleware]let listeners and DBAL middleware register themselves without manual service tagging - A Symfony profiler data collector showing per-request query counts, execution time, and duplicate-query warnings for performance debugging
Common Use Cases
- Standard relational-database persistence in any Symfony application — entity mapping, migrations (via
doctrine/doctrine-migrations-bundle), and repository queries - Multi-database or multi-tenant Symfony applications configuring several named connections and entity managers side by side
- Adding custom DBAL middleware (query logging, read/write splitting via
PrimaryReadReplicaConnection) without hand-registering services - Debugging N+1 queries and slow database calls during development using the Symfony profiler’s Doctrine panel
Under The Hood
Architecture — The bundle’s core is DependencyInjection/DoctrineExtension.php, a large compiler-time class that reads the doctrine.orm/doctrine.dbal configuration tree and registers Connection, EntityManagerInterface, and mapping-driver services (attribute, XML, or static PHP drivers) into the container; DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php and IdGeneratorPass.php run as compiler passes to wire custom repositories and ID generators discovered via service tags, keeping the bulk of the integration logic at container-build time rather than request time. Tech Stack — PHP 8.4+, built directly on doctrine/dbal ^4.0, doctrine/orm (dev dependency, ^3.4 for testing), and Symfony 6.4/7.0/8.0 components (dependency-injection, config, console, cache, doctrine-bridge); static analysis is enforced with PHPStan at strict-rules level plus the phpstan-symfony and phpstan-phpunit extensions, and style with doctrine/coding-standard. Code Quality — 31 PHPUnit test classes cover the DI extension, commands, cache warmers, and mapping drivers; the codebase is organized into clear single-responsibility directories (Command/, CacheWarmer/, Mapping/, Middleware/, Repository/, Attribute/), all under declare(strict_types=1), with CI running coverage via Codecov. API Design — Configuration is entirely declarative YAML with sane defaults, so a typical Symfony project needs only a connection URL to get a working EntityManager; the attribute-based listener/middleware registration (#[AsEntityListener], #[AsMiddleware]) and the autowiring ServiceEntityRepository base class substantially cut the boilerplate compared to wiring Doctrine into a non-Symfony PHP project by hand.
Used by 4 apps in this directory
Hyvor Relay
Devops · AI Development · Monitoring
Self-hosted, open-source email API that automates DNS, manages SMTP delivery, and provides deep observability — replacing SES, Mailgun, and SendGrid with infrastructure you fully own.
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.