Skip to content

Instantly share code, notes, and snippets.

@popovserhii
Last active June 5, 2019 05:11
Show Gist options
  • Save popovserhii/82bb4ebf53e508f3480e659f958921cd to your computer and use it in GitHub Desktop.
Save popovserhii/82bb4ebf53e508f3480e659f958921cd to your computer and use it in GitHub Desktop.
Integrating Doctrine 2 ORM and Migrations into Zend Expressive
<?php
/**
* config/cli-config.php
* For more details @see \DoctrineORMModule\Module
*
* Run next commands for Migrations work
* $ composer require doctrine/doctrine-orm-module
* $ composer require doctrine/migrations
*/
$container = require 'container.php';
/* @var $em \Doctrine\ORM\EntityManager */
$em = $container->get('doctrine.entity_manager.orm_default');
$configuration = $container->get('doctrine.migrations_configuration.orm_default');
return new \Symfony\Component\Console\Helper\HelperSet([
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em),
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'configuration' => new \Doctrine\DBAL\Migrations\Tools\Console\Helper\ConfigurationHelper($em->getConnection(), $configuration)
]);
<?php
/**
* config/autoload/doctrine.global.php
*
* @see https://www.jamestitcumb.com/posts/integrating-doctrine-expressive
*/
use Zend\Stdlib\ArrayUtils;
// @todo Exclude to Middleware (wait answer the question https://www.jamestitcumb.com/posts/integrating-doctrine-expressive)
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(
function ($className) {
return class_exists($className);
}
);
$vendorPath = __DIR__ . '/../../vendor'; // You may need to adjust this depending on your structure...
$doctrineModuleConfig = require_once $vendorPath . '/doctrine/doctrine-module/config/module.config.php';
$doctrineModuleConfig['dependencies'] = $doctrineModuleConfig['service_manager'];
unset($doctrineModuleConfig['service_manager']);
$doctrineOrmModuleConfig = require_once $vendorPath . '/doctrine/doctrine-orm-module/config/module.config.php';
$doctrineOrmModuleConfig['dependencies'] = $doctrineOrmModuleConfig['service_manager'];
unset($doctrineOrmModuleConfig['service_manager']);
return ArrayUtils::merge($doctrineModuleConfig, $doctrineOrmModuleConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment