Example #1
0
 protected function _initDoctrine()
 {
     $appDoctrineConfig = $this->getOption('doctrine');
     $classLoader = new DoctrineClassLoader('Doctrine');
     $classLoader->setIncludePath(realpath(APPLICATION_PATH . '/../library'));
     $classLoader->register();
     $config = new DoctrineConfiguration();
     if (isset($appDoctrineConfig['cache'])) {
         switch ($appDoctrineConfig['cache']) {
             case 'array':
                 $cache = new DoctrineArrayCache();
                 break;
             case 'apc':
                 $cache = new DoctrineApcCache();
                 break;
         }
         $config->setQueryCacheImpl($cache);
         $config->setMetadataCacheImpl($cache);
     }
     $proxyDir = empty($appDoctrineConfig['proxyDir']) ? APPLICATION_PATH . '/../library/Orm/Proxies' : $appDoctrineConfig['proxyDir'];
     $config->setProxyDir(realpath($proxyDir));
     $config->setProxyNamespace('Orm\\Proxies');
     $config->setAutoGenerateProxyClasses(false);
     $config->setEntityNamespaces(array('Orm\\Entity'));
     $config->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\StaticPHPDriver(realpath(APPLICATION_PATH . '/../library/Orm/Entity')));
     //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $config->setSQLLogger(null);
     $db = $this->getResource('db');
     $dbConfig = $db->getConfig();
     $connectionOptions = array('pdo' => $db->getConnection(), 'dbname' => $dbConfig['dbname']);
     $entityManager = DoctrineEntityManager::create($connectionOptions, $config);
     $entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     Registry::setEntityManager($entityManager);
     return $entityManager;
 }