Skip to content

@meotimdihia /gist:4d927e349a9bfa9c2674 secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
a.php
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\AnnotationReader;
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);
$config->setMetadataDriverImpl(
new AnnotationDriver(
new CachedReader(
new AnnotationReader(),
new ArrayCache()
),
$paths
)
);
$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
Something went wrong with that request. Please try again.