/**
*
*/
public function __construct($config = array())
{
$defaults = array('proxy' => array('auto' => true, 'path' => LITHIUM_APP_PATH . '/resources/tmp/cache/Doctrine/Proxies', 'namespace' => 'Doctrine\\Proxies'), 'useModelDriver' => true, 'mapping' => array('class' => null, 'path' => LITHIUM_APP_PATH . '/models'), 'configuration' => null, 'eventManager' => null, 'utf-8' => true);
$config = Set::merge($defaults, $config);
$configuration = $config['configuration'] ?: new Configuration();
$eventManager = $config['eventManager'] ?: new EventManager();
$configuration->setProxyDir($config['proxy']['path']);
$configuration->setProxyNamespace($config['proxy']['namespace']);
$configuration->setAutoGenerateProxyClasses($config['proxy']['auto']);
$configuration->setMetadataCacheImpl(new ArrayCache());
// Annotation Driver
$driver = $configuration->newDefaultAnnotationDriver(array(LITHIUM_APP_PATH . '/models'));
$configuration->setMetadataDriverImpl($driver);
// TODO: Not sure if this is required or not!
// if (!$config['useModelDriver']) {
// $configuration->setMetadataDriverImpl(new ModelDriver());
// }
$configuration->setSqlLogger(new SqlLogger());
$mapping = array('adapter' => 'driver', 'login' => 'user', 'database' => 'dbname');
foreach ($mapping as $source => $dest) {
if (isset($config[$source]) && !isset($config[$dest])) {
$config[$dest] = $config[$source];
unset($config[$source]);
}
}
$this->_em = EntityManager::create($config, $configuration, $eventManager);
$this->_sm = $this->_em->getConnection()->getSchemaManager();
if ($this->_em->getConnection()->getDriver() instanceof Driver\PDOMySql\Driver && $config['utf-8']) {
$this->_em->getEventManager()->addEventSubscriber(new MysqlSessionInit('utf8', 'utf8_unicode_ci'));
}
parent::__construct($config);
}