Location: PHPKode > projects > GnomePHP > peec-GnomePHP-b5a360b/gnomephp/doctrine/DoctrineConnection.php
<?php
namespace gnomephp\doctrine;
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Configuration;
/**
 * Some applications got multiple connections, extend this for per db connection.
 *
 * @author peec
 *
 */
abstract class DoctrineConnection{
	
	static private $autoloaderConnected = false;

	

	
	

	static private function loadAutoloader(){
		require GNOME_FW_PATH . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR . 'Doctrine'. DIRECTORY_SEPARATOR .'Common'. DIRECTORY_SEPARATOR .'ClassLoader.php';

		$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', (GNOME_FW_PATH . DIRECTORY_SEPARATOR . 'doctrine') );
		$classLoader->register(); // register on SPL autoload stack

		$classloader = new \Doctrine\Common\ClassLoader('Symfony', (GNOME_FW_PATH . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR . 'Doctrine') );
		$classloader->register();
	}



	static public function load(){
		if (!self::$autoloaderConnected){
			self::loadAutoloader();
			self::$autoloaderConnected = true;
		}
	}

	/**
	 * 
	 * @return Doctrine\ORM\EntityManager The entity manager of Doctrine.
	 */
	static protected function getNewEntityManager($gnomeConfigSet){
			
			$caceDriverClass = '\Doctrine\Common\Cache\\'.$gnomeConfigSet['cache_driver'];

			if (\gnomephp\Configuration::get('application', 'debug_mode') == true) {
				// $cache = new $caceDriverClass;
			} else {
				// $cache = new $caceDriverClass;
			}

			$config = new Configuration;
			// $config->setMetadataCacheImpl($cache);
			$driverImpl = $config->newDefaultAnnotationDriver(GNOME_APP_PATH . DIRECTORY_SEPARATOR . 'model');
			$config->setMetadataDriverImpl($driverImpl);
			// $config->setQueryCacheImpl($cache);
			$config->setProxyDir(GNOME_APP_PATH . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR . 'Proxies');
			$config->setProxyNamespace(GNOME_APP_NS . '\Doctrine\Proxies');

			if (\gnomephp\Configuration::get('application', 'debug_mode') == true) {
				$config->setAutoGenerateProxyClasses(true);
			} else {
				$config->setAutoGenerateProxyClasses(false);
			}



			return EntityManager::create($gnomeConfigSet, $config);
	}



}
Return current item: GnomePHP