С версии: 1.6
Автор: Kévin Dunglas (dunglas@gmail.com)
Наследование: extends CacheProvider
Пример #1
0
 private function initORM()
 {
     $config_pff = ServiceContainer::get('config');
     if (true === $config_pff->getConfigData('development_environment')) {
         $cache = new ArrayCache();
     } elseif ($this->redis) {
         $redis = new \Redis();
         if (!$redis->connect($this->redis_host, $this->redis_port)) {
             throw new PffException("Cannot connect to redis", 500);
         }
         if ($this->redis_password != '') {
             if (!$redis->auth($this->redis_password)) {
                 throw new PffException("Cannot auth to redis", 500);
             }
         }
         $cache = new RedisCache();
         $cache->setRedis($redis);
         $cache->setNamespace($this->_app->getConfig()->getConfigData('app_name'));
     } else {
         $cache = new ApcuCache();
         $cache->setNamespace($this->_app->getConfig()->getConfigData('app_name'));
     }
     $config = new Configuration();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setResultCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(ROOT . DS . 'app' . DS . 'models');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir(ROOT . DS . 'app' . DS . 'proxies');
     $config->setProxyNamespace('pff\\proxies');
     if (true === $config_pff->getConfigData('development_environment')) {
         $config->setAutoGenerateProxyClasses(true);
         $connectionOptions = $config_pff->getConfigData('databaseConfigDev');
     } else {
         $config->setAutoGenerateProxyClasses(false);
         $connectionOptions = $config_pff->getConfigData('databaseConfig');
     }
     $this->db = EntityManager::create($connectionOptions, $config);
     ServiceContainer::set()['dm'] = $this->db;
     $platform = $this->db->getConnection()->getDatabasePlatform();
     $platform->registerDoctrineTypeMapping('enum', 'string');
 }
Пример #2
0
 /**
  * @param string $namespace
  * @return void
  */
 public function setNamespace($namespace)
 {
     parent::setNamespace($namespace);
     $this->internalNamespace = $namespace;
 }