-
-
Save Orkin/8fe7d0efe15838c3ea290e95d3762c8f to your computer and use it in GitHub Desktop.
Integrating Doctrine 2 ORM and Migrations into Zend Expressive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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