sebrogala / xsv-doctrine
Middleware for Doctrine 2 integration with Zend Expressive
Requires
- php: ^7.1
- doctrine/orm: ^2.6
- ocramius/proxy-manager: ^2.2
- zendframework/zend-hydrator: ^2.4
- zendframework/zend-stdlib: ^3.1
Requires (Dev)
- composer/composer: >=1.0.0-alpha10
- phpunit/phpunit: ~5.0
This package is not auto-updated.
Last update: 2025-01-19 07:32:40 UTC
README
Middleware module which integrates Doctrine 2 with Zend Expressive 3.
Basic usage
From data
directory copy doctrine.local.php.dist
to config/autoload
folder and remove .dist
while saving
credentials to database.
File cli-config.php.dist
is needed inside config
directory, as it's responsible for console use of Doctrine.
Enabale module in config/config.php
:
$configManager = new ConfigManager([ //... Xsv\Doctrine\ConfigProvider::class, //... new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'), ]);
To get Entity Manager just use:
$em = $container->get(\Doctrine\ORM\EntityManager::class);
or as an alias:
$em = $container->get('entity-manager');
Create additional EntityManager
To create one it is required to create new Class or Interface and provide new configuration
for it's name. For example: inside src/App/Service
create SomeEntityManager
file:
<?php namespace App\Service; interface SomeEntityManager {}
Now inside config file, for example config/autoload/doctrine.local.php
:
<?php return [ 'doctrine' => [ \Doctrine\ORM\EntityManager::class => [ /* standard config here */ ], \App\Service\SomeEntityManager::class => [ /* Config for another EntityManager */ ], ], 'dependencies' => [ 'factories' => [ \App\Service\SomeEntityManager::class => EntityManagerFactory::class, ], ], ];
To use that EntityManager just get it from ServiceManager by newly created interface:
$someEntityManager = $container->get(\App\Service\SomeEntityManager::class);