Skip to content

Instantly share code, notes, and snippets.

@Orkin
Forked from popovserhii/cli-config.php
Created March 30, 2018 13:38
Show Gist options
  • Save Orkin/8fe7d0efe15838c3ea290e95d3762c8f to your computer and use it in GitHub Desktop.
Save Orkin/8fe7d0efe15838c3ea290e95d3762c8f 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