Skip to content

Instantly share code, notes, and snippets.

@meotimdihia
Created September 18, 2012 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meotimdihia/a14bb5eb08073fa74857 to your computer and use it in GitHub Desktop.
Save meotimdihia/a14bb5eb08073fa74857 to your computer and use it in GitHub Desktop.
doctrine.php
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
class Doctrine{
private $EntityManager;
public function __construct(){
$this->_initConfig();
$paths = array(MODELS_DIR . 'Entities');
$isDevMode = true;
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => $this->config['username'],
'password' => $this->config['password'],
'host' => $this->config['host'],
'dbname' => $this->config['dbname'],
'charset' => isset($this->config['charset']) ? $this->config['charset'] : 'UTF8'
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$em = EntityManager::create($dbParams, $config);
$conn = $em->getConnection();
$conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
$this->EntityManager = $em;
}
public function getEntityManager(){
return $this->EntityManager;
}
private function _initConfig()
{
if (defined('CONFIG_DIR') && file_exists(CONFIG_DIR. DS .'db.conf.php')) {
$configFile = CONFIG_DIR. DS .'db.conf.php';
}
else {
$configFile = GLOBAL_CONFIGS_DIR .DS .'db.conf.php';
}
$config = include $configFile;
$this->config = $config['database'][$config['default']];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment