This package provide Doctrine 2 factories for PRS-11 container standard.
Console run:
composer require streamcommon/doctrine-manager
Or add into your composer.json
:
"require": {
"streamcommon/doctrine-manager": "*"
}
- ORM version 2.6
- DBAL version 2.9
- Migrations version 2.1
- Event Manager version 1.0
- Metadata driver
- ORM Events
- Doctrine Annotation >1.6
- Caching
- Entity Manager
- ZendFramework/zend-servicemanager
- ZendFramework/zend-auradi-config
- ZendFramework/zend-pimple-config
- Jsoumelidis/zend-sf-di-config
- Laminas/laminas-servicemanager
- Laminas/laminas-auradi-config
- Laminas/laminas-pimple-config
Psr\Container\ContainerInterface
container MUST haveconfig
key
Configure your project config file:
- Configure doctrine configuration like:
'config' => [ 'doctrine' => [ 'configuration' => [ // If you use single connection 'orm_default' => [ 'result_cache' => 'array', 'metadata_cache' => 'array', 'query_cache' => 'array', 'hydration_cache' => 'array', 'driver' => 'orm_default', ], // If you want to add a second connection 'orm_custom' => [ 'result_cache' => 'memcached', 'metadata_cache' => 'memcached', 'query_cache' => 'memcached', 'hydration_cache' => 'memcached', 'driver' => 'orm_custom', ], ],
- Configure connection options like:
'connection' => [ // If you use single connection // Default using MySql connection 'orm_default' => [ 'configuration' => 'orm_default', 'event_manager' => 'orm_default', 'params' => [ 'dbname' => 'name', 'user' => 'user', 'password' => 'password', 'host' => 'localhost', ], ], // If you want to add a second connection // Alternative Postgress connection 'orm_custom' => [ 'configuration' => 'orm_custom', 'event_manager' => 'orm_custom', 'driver_class_name' => \Doctrine\DBAL\Driver\PDOPgSql\Driver::class, 'params' => [ 'dbname' => 'name', 'user' => 'user', 'password' => 'password', 'host' => 'localhost_custom', ], ] ],
- Configure entity|event manager:
'entity_manager' => [ 'orm_default' => [ 'connection' => 'orm_default', 'configuration' => 'orm_default', ], 'orm_custom' => [ 'connection' => 'orm_custom', 'configuration' => 'orm_custom', ] ], 'event_manager' => [ 'orm_default' => [ 'subscribers' => [], ], 'orm_custom' => [ 'subscribers' => [], ] ], 'entity_resolver' => [ 'orm_default' => [ 'resolvers' => [], ], 'orm_custom' => [ 'resolvers' => [], ], ],
- Configure orm driver, for example:
'driver' => [ // If you use single connection // Annotation driver example //@see https://www.doctrine-project.org/projects/doctrine-annotations/en/1.6/index.html 'orm_default' => [ 'class_name' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class, 'drivers' => [ 'Annotation\Entity' => 'Annotation\Entity' ], ], 'Annotation\Entity' => [ 'class_name' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class, 'paths' => [ __DIR__ . '/Annotation/Entity' ] ], // If you want to add a second connection // Php driver for example 'orm_custom' => [ 'class_name' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class, 'drivers' => [ 'PHPDriver\Entity' => 'PHPDriver\Entity' ], ], 'PHPDriver\Entity' => [ 'class_name' => \Doctrine\Common\Persistence\Mapping\Driver\PHPDriver::class, 'paths' => [ __DIR__ . '/PHPDriver/Entity' ] ], ],
- Configure doctrine cache:
//@see https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/caching.html 'cache' => [ 'array' => [ 'class_name' => Doctrine\Common\Cache\ArrayCache::class, 'namespace' => 'Streamcommon\Doctrine\Manager\Interop', ] ], ] ],
- Configure your project dependencies:
use Streamcommon\Doctrine\Manager\Common\Factory\{ Cache as CacheFactory, Driver as DriverFactory, EventManager as EventManagerFactory }; use Streamcommon\Doctrine\Manager\DBAL\Factory\Connection as ConnectionFactory; use Streamcommon\Doctrine\Manager\ORM\Factory\{ Configuration as ConfigurationFactory, EntityManager as EntityManagerFactory, EntityResolver as EntityResolverFactory, }; 'dependencies' => [ 'factories' => [ // If you use single connection 'doctrine.driver.orm_default' => [DriverFactory::class, 'orm_default'], 'doctrine.event_manager.orm_default' => [EventManagerFactory::class, 'orm_default'], 'doctrine.configuration.orm_default' => [ConfigurationFactory::class, 'orm_default'], 'doctrine.connection.orm_default' => [ConnectionFactory::class, 'orm_default'], 'doctrine.entity_resolver.orm_default' => [EntityResolverFactory::class, 'orm_default'], 'doctrine.entity_manager.orm_default' => [EntityManagerFactory::class, 'orm_default'], 'doctrine.cache.array' => [CacheFactory::class, 'orm_default'], // If you want to add a second connection 'doctrine.driver.orm_custom' => [DriverFactory::class, 'orm_custom'], 'doctrine.event_manager.orm_custom' => [EventManagerFactory::class, 'orm_custom'], 'doctrine.configuration.orm_custom' => [ConfigurationFactory::class, 'orm_custom'], 'doctrine.connection.orm_custom' => [ConnectionFactory::class, 'orm_custom'], 'doctrine.entity_resolver.orm_custom' => [EntityResolverFactory::class, 'orm_custom'], 'doctrine.entity_manager.orm_custom' => [EntityManagerFactory::class, 'orm_custom'], ], ]
- Use in your project:
$em = $container->get('doctrine.entity_manager.orm_default'); $connection = $container->get('doctrine.connection.orm_default');
Laminas ServiceManager
use Streamcommon\Doctrine\Manager\ConfigProvider;
use Laminas\ServiceManager\ServiceManager;
$config = new ConfigProvider();
$config = $config();
$dependencies = $config['dependencies'];
$dependencies['services']['config'] = $config;
return new ServiceManager($dependencies);
Symfony Container
use JSoumelidis\SymfonyDI\Config\{Config as SymfonyConfig, ContainerFactory as SymfonyContainerFactory};
use Streamcommon\Doctrine\Manager\ConfigProvider;
$config = new ConfigProvider();
$config = $config();
$dependencies = $config['dependencies'];
$dependencies['services']['config'] = $config;
$container = new SymfonyContainerFactory();
return $container(new SymfonyConfig($dependencies))
Etc...
- See
- For many connections was added a new
--object-manager
argument toorm
namespace:
Arguments:
--object-manager Doctrine object manager name [default: "orm_default"]