Пример #1
0
 public static function Config($prefix = "app_")
 {
     self::$config = new Doctrine\ORM\Configuration();
     // (2)
     // Proxy Configuration (3)
     self::$config->setProxyDir(__DIR__ . "/doctrine/proxy_cache");
     self::$config->setProxyNamespace(jf_Application_Name . '\\Proxies');
     self::$config->setAutoGenerateProxyClasses(jf::$RunMode->IsDevelop());
     // Mapping Configuration (4)
     //$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/entities/xml");
     //$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/config/mappings/yml");
     $driverImpl = self::$config->newDefaultAnnotationDriver(__DIR__ . "/../model");
     self::$config->setMetadataDriverImpl($driverImpl);
     // Caching Configuration (5)
     if (jf::$RunMode->IsDeploy() and function_exists("apc_exists")) {
         self::$cache = new \Doctrine\Common\Cache\ApcCache();
     } else {
         self::$cache = new \Doctrine\Common\Cache\ArrayCache();
     }
     self::$config->setMetadataCacheImpl(self::$cache);
     self::$config->setQueryCacheImpl(self::$cache);
     // database configuration parameters (6)
     $db = \jf\DatabaseManager::Configuration();
     $adapter = $db->Adapter;
     if ($adapter == "mysql" or $adapter == "mysqli" or !$adapter) {
         $adapter = "pdo_mysql";
     }
     $conn = array('driver' => $adapter, 'user' => $db->Username, 'password' => $db->Password, 'host' => $db->Host, 'dbname' => $db->DatabaseName, 'charset' => 'utf8', 'path' => $db->DatabaseName);
     require_once __DIR__ . "/doctrine/sqllogger.php";
     self::$config->setSQLLogger(new Doctrine\DBAL\Logging\jframeworkSQLLogger());
     // obtaining the entity manager (7)
     self::$eventManager = new Doctrine\Common\EventManager();
     self::$tablePrefix = new \Doctrine\Extensions\TablePrefix($prefix);
     self::$eventManager->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, self::$tablePrefix);
     self::$entityManager = \Doctrine\ORM\EntityManager::create($conn, self::$config, self::$eventManager);
 }