2017 © Pedro Peláez
 

library xsv-doctrine

Middleware for Doctrine 2 integration with Zend Expressive

image

sebrogala/xsv-doctrine

Middleware for Doctrine 2 integration with Zend Expressive

  • Friday, July 20, 2018
  • by SebRogala
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 43 % Grown

The README.md

Zend Expressive 3 Doctrine 2 Module

Middleware module which integrates Doctrine 2 with Zend Expressive 3., (*1)

Basic usage

From data directory copy doctrine.local.php.dist to config/autoload folder and remove .dist while saving credentials to database., (*2)

File cli-config.php.dist is needed inside config directory, as it's responsible for console use of Doctrine., (*3)

Enabale module in config/config.php:, (*4)

$configManager = new ConfigManager([
    //...
    Xsv\Doctrine\ConfigProvider::class,
    //...
    new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'),
]);

To get Entity Manager just use:, (*5)

$em = $container->get(\Doctrine\ORM\EntityManager::class);

or as an alias:, (*6)

$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:, (*7)

<?php

namespace App\Service;

interface SomeEntityManager {}

Now inside config file, for example config/autoload/doctrine.local.php:, (*8)

<?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:, (*9)

$someEntityManager = $container->get(\App\Service\SomeEntityManager::class);

The Versions