Esempio n. 1
0
 /**
  * constructor
  */
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require 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.'third_party/Doctrine/Common/ClassLoader.php';
     $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . '../vendor/doctrine');
     $doctrineClassLoader->register();
     $entitiesClassLoader = new ClassLoader('models', APPPATH . "models/Entities");
     $entitiesClassLoader->register();
     $proxiesClassLoader = new ClassLoader('proxies', APPPATH . 'models/proxies');
     $proxiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     //TODO this approach won't work always, developers may habe memcached installed, but not interested
     //to use or server not running. Need to fix.
     if (class_exists('Memcached')) {
         $memcache = new \Memcached();
         $memcache->addServer('127.0.0.1', 11211);
         $cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
         $cacheDriver->setMemcached($memcache);
     } else {
         if (extension_loaded('apc') && ini_get('apc.enabled')) {
             $cacheDriver = new \Doctrine\Common\Cache\ApcCache();
         } else {
             $cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
         }
     }
     $config->setMetadataCacheImpl($cacheDriver);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cacheDriver);
     // Proxy configuration
     $config->setProxyDir(APPPATH . 'models/proxies');
     $config->setProxyNamespace('Proxies');
     // Set up logger
     //$logger = new Doctrine\DBAL\Logging\CIProfiler();
     //$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);
     foreach ($driverImpl->getAllClassNames() as $class) {
         require_once $entitiesClassLoader->getIncludePath() . "/" . $class . ".php";
     }
     //$this->generate_classes();
 }
Esempio n. 2
0
 /**
  * constructor
  */
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require 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.'third_party/Doctrine/Common/ClassLoader.php';
     $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . '../vendor/doctrine');
     $doctrineClassLoader->register();
     $entitiesClassLoader = new ClassLoader('models', APPPATH . "models/Entities");
     $entitiesClassLoader->register();
     $proxiesClassLoader = new ClassLoader('proxies', APPPATH . 'models/proxies');
     $proxiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     // Proxy configuration
     $config->setProxyDir(APPPATH . 'models/proxies');
     $config->setProxyNamespace('Proxies');
     // Set up logger
     //$logger = new Doctrine\DBAL\Logging\CIProfiler();
     //$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);
     foreach ($driverImpl->getAllClassNames() as $class) {
         require_once $entitiesClassLoader->getIncludePath() . "/" . $class . ".php";
     }
     //$this->generate_classes();
 }