Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:48
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 doctrinebot/6b60950ed7325ed6606c to your computer and use it in GitHub Desktop.
Save doctrinebot/6b60950ed7325ed6606c to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-711 - https://github.com/doctrine/doctrine2/issues/5224
<?php
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSqlLogger;
class Doctrine {
public $em = null;
public function __construct()
{
// load database configuration from CodeIgniter
require_once APPPATH.'config/database.php';
// Set up class loading. You could use different autoloaders, provided by your favorite framework,
// if you want to.
require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';
$doctrineClassLoader = new ClassLoader('Doctrine', 'c:/xampp/xampplite/htdocs/CodeIgniter_1.7.2/ci/application/libraries');
$doctrineClassLoader->register();
$entitiesClassLoader = new ClassLoader('Entities', 'C:/xampp/xampplite/htdocs/CodeIgniter_1.7.2/ci/application');
$entitiesClassLoader->register();
$proxiesClassLoader = new ClassLoader('Proxies', 'c:/xampp/xampplite/htdocs/CodeIgniter_1.7.2/ci/application/Entities/proxies');
$proxiesClassLoader->register();
// Set up caches
$config = new Configuration;
$cache = new ArrayCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('c:/xampp/xampplite/htdocs/CodeIgniter_1.7.2/ci/application/Entities');
$config->setMetadataDriverImpl($driverImpl);
// Proxy configuration
$config->setProxyDir('c:/xampp/xampplite/htdocs/CodeIgniter_1.7.2/ci/application/Entities/proxies');
$config->setProxyNamespace('Proxies');
// Set up logger
$logger = new EchoSqlLogger;
$config->setSqlLogger($logger);
$config->setAutoGenerateProxyClasses( TRUE );
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database']
);
// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment