예제 #1
0
파일: Flexistore.php 프로젝트: kisma/kisma
 /**
  * @param string $type
  * @param string $namespace
  *
  * @throws \InvalidArgumentException
  * @internal param string $storeId
  */
 public function __construct($type = CacheTypes::ARRAY_CACHE, $namespace = null)
 {
     if (!CacheTypes::contains($type)) {
         throw new \InvalidArgumentException('The $type "' . $type . '" is not valid.');
     }
     $_class = static::STORE_NAMESPACE . $type . 'Cache';
     $_mirror = new \ReflectionClass($_class);
     $this->_store = $_mirror->getConstructor() ? $_mirror->newInstanceArgs($this->_getCacheTypeArguments($type)) : $_mirror->newInstance();
     if (null !== $namespace) {
         $this->_store->setNamespace($namespace);
     }
     $this->_initializeCache($type);
 }
예제 #2
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $redis = $serviceLocator->get('redis');
     $config = $serviceLocator->get('ApplicationConfig');
     if (is_array($config) && isset($config['tenant_id'])) {
         if ($redis instanceof \Redis) {
             $cache = new RedisCache();
             $cache->setNamespace(sprintf('stokq.doctrine.%s', $config['tenant_id']));
             $cache->setRedis($redis);
             return $cache;
         }
     } else {
         throw new \RuntimeException("Unable to get `tenant_id` from config.");
     }
     throw new \RuntimeException("Invalid redis instance returned.");
 }
예제 #3
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');
 }
예제 #4
0
 /**
  * @param string $namespace
  * @return void
  */
 public function setNamespace($namespace)
 {
     parent::setNamespace($namespace);
     $this->internalNamespace = $namespace;
 }
예제 #5
0
 public function clean($prefix)
 {
     $this->redis_cache->setNamespace($prefix);
     return $this->redis_cache->deleteAll();
 }
예제 #6
0
파일: boot.php 프로젝트: TonyWoo/website
use Destiny\Common\Application;
use Destiny\Common\Routing\Router;
use Destiny\Common\ControllerAnnotationLoader;
use Destiny\Common\DirectoryClassIterator;
use Doctrine\Common\Annotations\AnnotationReader;
// This should be in the server config
ini_set('date.timezone', 'UTC');
// Used when the full path is needed to the base directory
define('_BASEDIR', realpath(__DIR__ . '/../'));
define('PP_CONFIG_PATH', _BASEDIR . '/config/');
$loader = (require _BASEDIR . '/vendor/autoload.php');
Config::load(array_replace_recursive(require _BASEDIR . '/config/config.php', require _BASEDIR . '/config/config.local.php', json_decode(file_get_contents(_BASEDIR . '/composer.json'), true)));
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$app = Application::instance();
$app->setLoader($loader);
$log = new Logger('web');
$log->pushHandler(new StreamHandler(Config::$a['log']['path'] . 'web.log', Logger::CRITICAL));
$log->pushProcessor(new Monolog\Processor\WebProcessor());
$app->setLogger($log);
$app->setConnection(DriverManager::getConnection(Config::$a['db']));
$redis = new Redis();
$redis->connect(Config::$a['redis']['host'], Config::$a['redis']['port']);
$redis->select(Config::$a['redis']['database']);
$app->setRedis($redis);
$cache = new RedisCache();
$cache->setRedis($app->getRedis());
$cache->setNamespace(Config::$a['cache']['namespace']);
$app->setCacheDriver($cache);
$app->setRouter(new Router());
$app->setAnnotationReader(new Doctrine\Common\Annotations\CachedReader(new AnnotationReader(), $cache, $debug = false));
ControllerAnnotationLoader::loadClasses(new DirectoryClassIterator(_BASEDIR . '/lib/', 'Destiny/Controllers/'), $app->getAnnotationReader(), $app->getRouter());