Skip to content

Instantly share code, notes, and snippets.

@harikt
Created August 17, 2015 06:54
Show Gist options
  • Save harikt/1602f0d9e3c89659198a to your computer and use it in GitHub Desktop.
Save harikt/1602f0d9e3c89659198a to your computer and use it in GitHub Desktop.
Configuring Doctrine ORM Entity Manager with Aura.Di
<?php
$di->set('entity_manager', function () {
// paths
$paths = array(__DIR__);
$isDevMode = false;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => getenv('username'),
'password' => getenv('password'),
'dbname' => getenv('dbname'),
);
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = \Doctrine\ORM\EntityManager::create($dbParams, $config);
return $entityManager;
});
// $entity_manager = $di->get('entity_manager');
@harikt
Copy link
Author

harikt commented Aug 17, 2015

iirc what I tried to do was something like

$di->params['Doctrine\DBAL\Connection']['params'] = 
$di->params['Doctrine\DBAL\Connection']['driver'] = 'pdo_mysql';
$di->params['Doctrine\DBAL\Connection']['config']
$di->params['Doctrine\DBAL\Connection']['eventManager']
        // , Driver $driver, Configuration $config = null, EventManager $eventManager = null =
$di->params['Doctrine\ORM\EntityManager']['conn']
$di->params['Doctrine\ORM\EntityManager']['config']
$di->params['Doctrine\ORM\EntityManager']['eventManager']

but this is very complicated and may be I ended up at the above gist itself if I am correct. There are a lot of experimental projects that I was unable to find :( . In case I came across will update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment