chubbyphp / chubbyphp-laminas-config-doctrine
Package info
github.com/chubbyphp/chubbyphp-laminas-config-doctrine
pkg:composer/chubbyphp/chubbyphp-laminas-config-doctrine
Requires
- php: ^8.3
- chubbyphp/chubbyphp-laminas-config-factory: ^1.5.3
- doctrine/common: ^3.5
- doctrine/event-manager: ^2.1.1
- psr/container: ^1.1.2|^2.0.2
- symfony/cache: ^6.4.45|^7.4.18|^8.1.6
- symfony/console: ^6.4.45|^7.4.18|^8.1.6
- symfony/var-exporter: ^6.4.45|^7.4.18
Requires (Dev)
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-laminas-config: ^1.5.3
- chubbyphp/chubbyphp-mock: ^2.2.2
- dg/bypass-finals: ^1.11.0
- doctrine/dbal: ^4.4.4
- doctrine/mongodb-odm: ^2.17.1
- doctrine/orm: ^3.6.8
- infection/infection: ^0.35.4
- mongodb/mongodb: ^1.21.4|^2.2.0
- php-coveralls/php-coveralls: ^2.9.1
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.2.13
- phpunit/phpunit: ^12.5.34
- ramsey/uuid: ^4.9.3
Suggests
None
Provides
None
Conflicts
- doctrine/dbal: <4.4.1 || >=5.0
- doctrine/mongodb-odm: <2.15.3 || >=3.0
- doctrine/orm: <3.6.1 || >=4.0
- mongodb/mongodb: <1.21.3 || >=2.0 <2.1.2 || >=3.0
Replaces
None
README
Description
Service factories that wire Doctrine (DBAL, ORM and MongoDB ODM) into a PSR-11 container from plain array
configuration. They follow the laminas/laminas-servicemanager dependencies convention, so they work with
chubbyphp/chubbyphp-container through chubbyphp/chubbyphp-laminas-config, with Mezzio, and with any other
container that understands the same configuration format (Aura.Di, Pimple, Auryn, Symfony, PHP-DI, ...).
What you get:
- Factories for the DBAL
Connection, the ORMEntityManager, the MongoDBClientand the ODMDocumentManager, plus theirConfigurationandEventManagerobjects. - Factories for the Symfony cache adapters Doctrine uses for metadata, query and result caching (array, APCu, chain, filesystem, memcached, PHP files, redis).
- A
ClassMapDriverthat lets you write mappings as small PHP classes instead of attributes, XML or YAML. - Factories for the Doctrine console commands (schema tool, cache clearing, proxies, hydrators, ...) and
dbal:database:create/dbal:database:dropcommands. - Support for multiple named connections, entity managers and document managers (for example
readandwrite) from the same set of factories.
Services are registered under their class name (for example EntityManagerInterface::class) rather than under
doctrine.something string keys, and only the Doctrine packages you actually use have to be installed.
The concept is based on dasprid/container-interop-doctrine by @DASPRiD, now maintained as roave/psr-container-doctrine.
Requirements
- php: ^8.3
- chubbyphp/chubbyphp-laminas-config-factory: ^1.5.3
- doctrine/common: ^3.5
- doctrine/event-manager: ^2.1.1
- psr/container: ^1.1.2|^2.0.2
- symfony/cache: ^6.4.45|^7.4.18|^8.1.6
- symfony/console: ^6.4.45|^7.4.18|^8.1.6
- symfony/var-exporter: ^6.4.45|^7.4.18
Suggested
Install only what you need:
- For the ORM: doctrine/dbal: ^4.4.4 and doctrine/orm: ^3.6.8
- For the MongoDB ODM: doctrine/mongodb-odm: ^2.17.1 and mongodb/mongodb: ^1.21.4|^2.2.0
Installation
Through Composer as chubbyphp/chubbyphp-laminas-config-doctrine.
composer require chubbyphp/chubbyphp-laminas-config-doctrine "^3.1.3"
Then add the Doctrine packages for the storage you use:
# ORM composer require doctrine/dbal doctrine/orm # MongoDB ODM composer require doctrine/mongodb-odm mongodb/mongodb
Usage
Each factory reads its options from the doctrine section of the container configuration and only needs the
dependencies.factories entry to be registered. A minimal ORM setup looks like this:
'dependencies' => [ 'factories' => [ CacheItemPoolInterface::class => ArrayAdapterFactory::class, EntityManagerInterface::class => EntityManagerFactory::class, MappingDriver::class => ClassMapDriverFactory::class, ], ], 'doctrine' => [ 'cache' => ['array' => ['namespace' => 'doctrine']], 'dbal' => ['connection' => ['driver' => 'pdo_pgsql', 'host' => 'localhost', 'dbname' => 'sample', /* ... */]], 'driver' => ['classMap' => ['map' => [Sample::class => SampleMapping::class]]], 'orm' => [ 'configuration' => [ 'metadataCache' => CacheItemPoolInterface::class, 'metadataDriverImpl' => MappingDriver::class, 'proxyDir' => '/tmp/doctrine/orm/proxies', 'proxyNamespace' => 'DoctrineORMProxy', ], ], ],
Good to know:
- Configuration values are resolved through the container. Any string value that matches a registered service
name is replaced by that service, so
'metadataCache' => CacheItemPoolInterface::classinjects the configured cache adapter. Keys underconfigurationmap to setters on the DoctrineConfigurationobject (proxyDircallssetProxyDir()), so every option Doctrine offers is available. - Dependencies are resolved lazily. The
EntityManagerFactorylooks upConnection::class,Configuration::classandEventManager::classin the container. If they are not registered, it builds them with the matching factory from this package, so you only register what you want to access directly. - Multiple instances share the same factories. Register a factory as
[EntityManagerFactory::class, 'read']under the service nameEntityManagerInterface::class.'read', and nest the related configuration under areadkey. The factory then resolves all of its dependencies with the samereadsuffix.
MongodbODM
ORM
Console commands
Register the command factories from ServiceFactory\DBAL\Tools\Console\Command,
ServiceFactory\ORM\Tools\Console\Command and ServiceFactory\ODM\MongoDB\Tools\Console\Command and add the
resulting commands to your Symfony console application. The commands pick the right instance by name:
--connection=<name> for DBAL, --em=<name> for the ORM and --dm=<name> for the MongoDB ODM. Without the
option the default (unsuffixed) service is used.
Copyright
2026 Dominik Zogg