PHPackages                             kadudutra/psr-container-doctrine - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kadudutra/psr-container-doctrine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kadudutra/psr-container-doctrine
================================

Doctrine Factories for PSR-11 Containers

0914PHP

Since Feb 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kadudutra/psr-container-doctrine)[ Packagist](https://packagist.org/packages/kadudutra/psr-container-doctrine)[ RSS](/packages/kadudutra-psr-container-doctrine/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

psr-container-doctrine: Doctrine Factories for PSR-11 Containers
================================================================

[](#psr-container-doctrine-doctrine-factories-for-psr-11-containers)

[![Latest Stable Version](https://camo.githubusercontent.com/1bb992c2a99f685a0c1735ca23b9d0aec3dc05e72f0c623917ebbcb7668278ba/68747470733a2f2f706f7365722e707567782e6f72672f726f6176652f7073722d636f6e7461696e65722d646f637472696e652f762f737461626c65)](https://packagist.org/packages/roave/psr-container-doctrine)[![Total Downloads](https://camo.githubusercontent.com/ce215c5d1f776e10a418802118467806f6b1b9a48fe38317b7c3363c3f76a696/68747470733a2f2f706f7365722e707567782e6f72672f726f6176652f7073722d636f6e7461696e65722d646f637472696e652f646f776e6c6f616473)](https://packagist.org/packages/roave/psr-container-doctrine)[![Build Status](https://camo.githubusercontent.com/2968ace3468c0dd697c79931186baee2a6765e92dc3f25b06f900d5e6ca5af37/68747470733a2f2f6170692e7472617669732d63692e6f72672f726f6176652f7073722d636f6e7461696e65722d646f637472696e652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/roave/psr-container-doctrine)[![Coverage Status](https://camo.githubusercontent.com/14f1dd7935ae93ddbe91055afef4105e70ee839a1337b3fb571a34beda8afadd/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f726f6176652f7073722d636f6e7461696e65722d646f637472696e652f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/roave/psr-container-doctrine)

[Doctrine](https://github.com/doctrine) factories for [PSR-11 containers](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md).

This package provides a set of factories to be used with containers using the PSR-11 standard for an easy Doctrine integration in a project. This project was originally written by [@DASPRiD](https://github.com/DASPRiD/container-interop-doctrine) but maintenance has been taken over by Roave.

Installation
------------

[](#installation)

The easiest way to install this package is through composer:

```
$ composer require roave/psr-container-doctrine
```

Configuration
-------------

[](#configuration)

In the general case where you are only using a single connection, it's enough to define the entity manager factory:

```
return [
    'dependencies' => [
        'factories' => [
            'doctrine.entity_manager.orm_default' => \KaduDutra\PsrContainerDoctrine\EntityManagerFactory::class,
        ],
    ],
];
```

If you want to add a second connection, or use another name than "orm\_default", you can do so by using the static variants of the factories:

```
return [
    'dependencies' => [
        'factories' => [
            'doctrine.entity_manager.orm_other' => [\KaduDutra\PsrContainerDoctrine\EntityManagerFactory::class, 'orm_other'],
        ],
    ],
];
```

You can also define an alias to retrieve an entity manager instance using `::class` capability:

```
return [
    'aliases' => [
        'doctrine.entity_manager.orm_default' => Doctrine\ORM\EntityManagerInterface::class,
    ],
];
```

Each factory supplied by this package will by default look for a registered factory in the container. If it cannot find one, it will automatically pull its dependencies from on-the-fly created factories. This saves you the hassle of registering factories in your container which you may not need at all. Of course, you can always register those factories when required. The following additional factories are available:

- `\KaduDutra\PsrContainerDoctrine\CacheFactory` (doctrine.cache.\*)
- `\KaduDutra\PsrContainerDoctrine\ConnectionFactory` (doctrine.connection.\*)
- `\KaduDutra\PsrContainerDoctrine\ConfigurationFactory` (doctrine.configuration.\*)
- `\KaduDutra\PsrContainerDoctrine\DriverFactory` (doctrine.driver.\*)
- `\KaduDutra\PsrContainerDoctrine\EventManagerFactory` (doctrine.event\_manager.\*)

Each of those factories supports the same static behavior as the entity manager factory. For container specific configurations, there are a few examples provided in the example directory:

- [Aura.Di](example/aura-di.php)
- [PimpleInterop](example/pimple-interop.php)
- [Laminas\\ServiceManager](example/laminas-servicemanager.php)

Example configuration
---------------------

[](#example-configuration)

A complete example configuration can be found in [example/full-config.php](example/full-config.php). Please note that the values in there are the defaults, and don't have to be supplied when you are not changing them. Keep your own configuration as minimal as possible. A minimal configuration can be found in [example/minimal-config.php](example/minimal-config.php)

Migrations
----------

[](#migrations)

If you want to expose the migration commands, you have to map the command name to `CommandFactory`. This factory needs migrations config setup. For `ExecuteCommand` example:

```
return [
    'dependencies' => [
        'factories' => [
            \Doctrine\Migrations\Tools\Console\Command\ExecuteCommand::class => \KaduDutra\PsrContainerDoctrine\Migrations\CommandFactory::class,

            // Optionally, you could make your container aware of additional factories as of migrations release v3.0:
            \Doctrine\Migrations\Configuration\Migration\ConfigurationLoader::class => \KaduDutra\PsrContainerDoctrine\ConfigurationLoaderFactory::class,
            \Doctrine\Migrations\DependencyFactory::class => \KaduDutra\PsrContainerDoctrine\Migrations\DependencyFactoryFactory::class,
        ],
    ],
];
```

You can find a full list of available commands in [example/full-config.php](example/full-config.php).

Using the Doctrine CLI
----------------------

[](#using-the-doctrine-cli)

In order to be able to use the CLI tool of Doctrine, you need to set-up a `cli-config.php` file in your project directory. That file is generally quite short, and should look something like this for you:

```
