Search by

chubbyphp / chubbyphp-laminas-config-doctrine

dominikzogg

Package info

github.com/chubbyphp/chubbyphp-laminas-config-doctrine

pkg:composer/chubbyphp/chubbyphp-laminas-config-doctrine

Statistics

Installs: 14 711

Dependents: 1

Suggesters: 0

Stars: 8

Open Issues: 0

3.1.5 2026-09-11 17:23 UTC

README

CI Coverage Status Mutation testing badge Latest Stable Version Total Downloads Monthly Downloads

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

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 ORM EntityManager, the MongoDB Client and the ODM DocumentManager, plus their Configuration and EventManager objects.
  • Factories for the Symfony cache adapters Doctrine uses for metadata, query and result caching (array, APCu, chain, filesystem, memcached, PHP files, redis).
  • A ClassMapDriver that 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:drop commands.
  • Support for multiple named connections, entity managers and document managers (for example read and write) 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

Suggested

Install only what you need:

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::class injects the configured cache adapter. Keys under configuration map to setters on the Doctrine Configuration object (proxyDir calls setProxyDir()), so every option Doctrine offers is available.
  • Dependencies are resolved lazily. The EntityManagerFactory looks up Connection::class, Configuration::class and EventManager::class in 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 name EntityManagerInterface::class.'read', and nest the related configuration under a read key. The factory then resolves all of its dependencies with the same read suffix.

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