private function initDm() { $config = new Configuration(); $conn = new Connection($this->_config->getConfigData('mongo_server')); if (true === $this->_config->getConfigData('development_environment')) { $cache = new ArrayCache(); $config->setAutoGenerateHydratorClasses(true); $config->setAutoGenerateProxyClasses(true); } else { $cache = new ApcCache(array('prefix' => $this->_app->getConfig()->getConfigData('app_name'))); $config->setAutoGenerateHydratorClasses(false); $config->setAutoGenerateProxyClasses(false); } $config->setMetadataCacheImpl($cache); $config->setProxyDir(ROOT . DS . 'app' . DS . 'proxies'); $config->setProxyNamespace('Proxies'); $config->setHydratorDir(ROOT . DS . 'app' . DS . 'hydrators'); $config->setHydratorNamespace('Hydrators'); $config->setDefaultDB($this->_config->getConfigData('mongo_dbName')); $config->setMetadataDriverImpl(AnnotationDriver::create(ROOT . DS . 'app' . DS . 'models')); AnnotationDriver::registerAnnotationClasses(); $this->_dm = DocumentManager::create($conn, $config); ServiceContainer::set()['dm'] = $this->_dm; }
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'); }
/** * General bootstrap operations for the framework. * * @author paolo.fagni<at>gmail.com */ \pff\Core\ServiceContainer::initPimple(); \pff\Core\ServiceContainer::set()['config'] = function ($c) { return new \pff\Config(); }; \pff\Core\ServiceContainer::set()['hookmanager'] = function ($c) { return new \pff\Core\HookManager(); }; \pff\Core\ServiceContainer::set()['modulemanager'] = function ($c) { return new \pff\Core\ModuleManager(); }; \pff\Core\ServiceContainer::set()['helpermanager'] = function ($c) { return new \pff\Core\HelperManager(); }; \pff\Core\ServiceContainer::set()['app'] = function ($c) { return new \pff\App(); }; \pff\Core\ServiceContainer::set()['yamlparser'] = function ($c) { return new \Symfony\Component\Yaml\Parser(); }; $app = \pff\Core\ServiceContainer::get('app'); $app->setUrl($url); $app->setErrorReporting(); $app->removeMagicQuotes(); $app->unregisterGlobals(); \pff\Core\ServiceContainer::get('modulemanager')->initModules(); // @codeCoverageIgnoreStop