Ejemplo n.º 1
0
 public function init()
 {
     parent::init();
     if (!$this->isComponentActive()) {
         return;
     }
     try {
         $this->userInfo = call_user_func($this->userInfoCallable);
         $this->setUser($this->userInfo);
         $memcacheServerName = $this->cacheServer['host'];
         $memcacheServerPort = $this->cacheServer['port'];
         if ($memcacheServerName && $memcacheServerPort) {
             $memcached = new \Memcached();
             $memcached->addServer($memcacheServerName, $memcacheServerPort);
             $cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
             $cacheDriver->setMemcached($memcached);
             $cacheStorage = new \Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage($cacheDriver);
         } else {
             $cacheStorage = new \Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage(new \Doctrine\Common\Cache\FilesystemCache('/tmp/'));
         }
         $this->client = new \LaunchDarkly\LDClient($this->apiKey, array("cache" => $cacheStorage));
         $this->featureToggleUser = (new \LaunchDarkly\LDUserBuilder($this->user->key))->secondary($this->user->secondary)->ip($this->user->ip)->country($this->user->country)->email($this->user->email)->name($this->user->name)->avatar($this->user->avatar)->firstName($this->user->firstName)->lastName($this->user->lastName)->anonymous($this->user->anonymous)->custom(array('type' => $this->user->type, 'parentCompanyId' => $this->user->parentId, 'referredAccountId' => $this->user->referredAccountId, 'channel' => $this->user->channel, 'payoutMethod' => isset($this->user->payoutMethod) ? $this->user->payoutMethod : null))->build();
     } catch (\Exception $ex) {
         $this->componentActive = false;
         \Yii::log("Cannot initiate Feature Toggles: {$ex->getMessage()}", \CLogger::LEVEL_WARNING, 'system.featureToggle');
     }
 }
Ejemplo n.º 2
0
 /**
  * constructor
  */
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require APPPATH . 'config/database.php';
     // Set up class loading. You could use different autoloaders, provided by your favorite framework,
     // if you want to.
     //require_once APPPATH.'third_party/Doctrine/Common/ClassLoader.php';
     $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . '../vendor/doctrine');
     $doctrineClassLoader->register();
     $entitiesClassLoader = new ClassLoader('models', APPPATH . "models/Entities");
     $entitiesClassLoader->register();
     $proxiesClassLoader = new ClassLoader('proxies', APPPATH . 'models/proxies');
     $proxiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     //TODO this approach won't work always, developers may habe memcached installed, but not interested
     //to use or server not running. Need to fix.
     if (class_exists('Memcached')) {
         $memcache = new \Memcached();
         $memcache->addServer('127.0.0.1', 11211);
         $cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
         $cacheDriver->setMemcached($memcache);
     } else {
         if (extension_loaded('apc') && ini_get('apc.enabled')) {
             $cacheDriver = new \Doctrine\Common\Cache\ApcCache();
         } else {
             $cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
         }
     }
     $config->setMetadataCacheImpl($cacheDriver);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cacheDriver);
     // Proxy configuration
     $config->setProxyDir(APPPATH . 'models/proxies');
     $config->setProxyNamespace('Proxies');
     // Set up logger
     //$logger = new Doctrine\DBAL\Logging\CIProfiler();
     //$config->setSQLLogger($logger);
     $config->setAutoGenerateProxyClasses(TRUE);
     // Database connection information
     $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']);
     // Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config);
     foreach ($driverImpl->getAllClassNames() as $class) {
         require_once $entitiesClassLoader->getIncludePath() . "/" . $class . ".php";
     }
     //$this->generate_classes();
 }
 /**
  * Get cache driver according to config.yml entry.
  *
  * Logic from Doctrine setup method
  * https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Setup.php#L122
  *
  * @param  array      $cacheConfig
  * @param  boolean    $isDevMode
  * @param  string|null $proxyDir
  * @return Cache
  */
 protected function getManuallyDefinedCache(array $cacheConfig, $isDevMode = false, $proxyDir = null)
 {
     $proxyDir = $proxyDir ?: sys_get_temp_dir();
     if ($isDevMode === false) {
         if (extension_loaded('apc') && !empty($cacheConfig['type']) && $cacheConfig['type'] == 'apc') {
             $cache = new \Doctrine\Common\Cache\ApcCache();
         } elseif (extension_loaded('xcache') && !empty($cacheConfig['type']) && $cacheConfig['type'] == 'xcache') {
             $cache = new \Doctrine\Common\Cache\XcacheCache();
         } elseif (extension_loaded('memcache') && !empty($cacheConfig['type']) && $cacheConfig['type'] == 'memcache') {
             $memcache = new \Memcache();
             $host = !empty($cacheConfig['host']) ? $cacheConfig['host'] : '127.0.0.1';
             if (!empty($cacheConfig['port'])) {
                 $memcache->connect($host, $cacheConfig['port']);
             } else {
                 $memcache->connect($host);
             }
             $cache = new \Doctrine\Common\Cache\MemcacheCache();
             $cache->setMemcache($memcache);
         } elseif (extension_loaded('memcached') && !empty($cacheConfig['type']) && $cacheConfig['type'] == 'memcached') {
             $memcached = new \Memcached();
             $host = !empty($cacheConfig['host']) ? $cacheConfig['host'] : '127.0.0.1';
             $port = !empty($cacheConfig['port']) ? $cacheConfig['port'] : 11211;
             $memcached->addServer($host, $port);
             $cache = new \Doctrine\Common\Cache\MemcachedCache();
             $cache->setMemcached($memcached);
         } elseif (extension_loaded('redis') && !empty($cacheConfig['type']) && $cacheConfig['type'] == 'redis') {
             $redis = new \Redis();
             $host = !empty($cacheConfig['host']) ? $cacheConfig['host'] : '127.0.0.1';
             if (!empty($cacheConfig['port'])) {
                 $redis->connect($host, $cacheConfig['port']);
             } else {
                 $redis->connect($host);
             }
             $cache = new \Doctrine\Common\Cache\RedisCache();
             $cache->setRedis($redis);
         } else {
             $cache = new ArrayCache();
         }
     } else {
         $cache = new ArrayCache();
     }
     if ($cache instanceof CacheProvider) {
         $cache->setNamespace("dc2_" . md5($proxyDir) . "_");
         // to avoid collisions
     }
     return $cache;
 }
 /**
  * 
  * 获取缓存信息
  * @return \Doctrine\Common\Cache\MongoDBCache
  */
 protected function getCache()
 {
     $namespace = 'PanGuKTD_ORM_';
     $cacheConfig = config('doctrine');
     $cacheName = $cacheConfig['name'];
     $cache = null;
     if ($cacheName == 'array') {
         $cache = new \Doctrine\Common\Cache\ArrayCache();
     } elseif ($cacheName == 'xcache') {
         $cache = new \Doctrine\Common\Cache\XcacheCache();
     } elseif ($cacheName == 'memcached') {
         $memcached = new \Memcached();
         $memcached->addServers($cacheConfig['memcached']);
         $cache = new \Doctrine\Common\Cache\MemcachedCache();
         $cache->setMemcached($memcached);
         $cache->setNamespace($namespace);
     } elseif ($cacheName == 'memcache') {
         $memcache = new \Memcache();
         foreach ($cacheConfig['memcache'] as $key => $value) {
             $memcache->addServer($value['host'], $value['port'], $value['persistent'], $value['weight']);
         }
         $cache = new \Doctrine\Common\Cache\MemcacheCache();
         $cache->setMemcache($memcache);
         $cache->setNamespace($namespace);
     } elseif ($cacheName == 'apc') {
         $cache = new \Doctrine\Common\Cache\ApcCache();
         $cache->setNamespace($namespace);
     } elseif ($cacheName == 'mongo') {
         $host = $cacheConfig['mongo']['host'];
         $port = $cacheConfig['mongo']['port'];
         $opt = $cacheConfig['mongo']['options'];
         $mongo = new \MongoClient("mongodb://{$host}:{$port}", $opt);
         $mongo = new \MongoDB($mongo, 'doctrine_orm_cache');
         $conn = new \MongoCollection($mongo, $namespace);
         $cache = new \Doctrine\Common\Cache\MongoDBCache($conn);
         $cache->setNamespace($namespace);
     } elseif ($cacheName == 'redis') {
         $host = $cacheConfig['redis']['host'];
         $port = $cacheConfig['redis']['port'];
         $redis = new \Redis();
         $redis->connect($host, $port);
         $cache = new \Doctrine\Common\Cache\RedisCache();
         $cache->setRedis($redis);
     }
     return $cache;
 }
Ejemplo n.º 5
0
 public function __call($method, $args)
 {
     $driver = null;
     switch (config()->cache_driver()) {
         case 'memcached':
             $memcached = new \Memcached();
             $memcached->addServer(config()->cache_host(), 11211);
             $driver = new \Doctrine\Common\Cache\MemcachedCache();
             $driver->setMemcached($memcached);
             break;
         case 'apc':
             $driver = new \Doctrine\Common\Cache\ApcCache();
             break;
     }
     switch ($method) {
         case 'set':
             // $driver->delete($args[0]);
             $driver->save($args[0], json_encode($args[1]));
             break;
         case 'get':
             return json_decode($driver->fetch($args[0]));
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * Detects the correct doctrine cache driver for the user caching engine in use
  * @return \Doctrine\Common\Cache\AbstractCache The doctrine cache driver object
  */
 public function getDoctrineCacheDriver()
 {
     if ($this->doctrineCacheEngine) {
         // return cache engine if already set
         return $this->doctrineCacheEngine;
     }
     $userCacheEngine = $this->getUserCacheEngine();
     // check if user caching is active
     if (!$this->getUserCacheActive()) {
         $userCacheEngine = \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_OFF;
     }
     switch ($userCacheEngine) {
         case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_APC:
             $cache = new \Doctrine\Common\Cache\ApcCache();
             $cache->setNamespace($this->getCachePrefix());
             break;
         case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_MEMCACHE:
             $memcache = $this->getMemcache();
             $cache = new \Doctrine\Common\Cache\MemcacheCache();
             $cache->setMemcache($memcache);
             $cache->setNamespace($this->getCachePrefix());
             break;
         case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_MEMCACHED:
             $memcached = $this->getMemcached();
             $cache = new \Doctrine\Common\Cache\MemcachedCache();
             $cache->setMemcached($memcached);
             $cache->setNamespace($this->getCachePrefix());
             break;
         case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_XCACHE:
             $cache = new \Doctrine\Common\Cache\XcacheCache();
             $cache->setNamespace($this->getCachePrefix());
             break;
         case \Cx\Core_Modules\Cache\Controller\Cache::CACHE_ENGINE_FILESYSTEM:
             $cache = new \Cx\Core_Modules\Cache\Controller\Doctrine\CacheDriver\FileSystemCache($this->strCachePath);
             break;
         default:
             $cache = new \Doctrine\Common\Cache\ArrayCache();
             break;
     }
     // set the doctrine cache engine to avoid getting it a second time
     $this->doctrineCacheEngine = $cache;
     return $cache;
 }
    }
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
    require $fileName;
});
use Ray\Di\Config;
class Module extends \Ray\Di\AbstractModule
{
    public function configure()
    {
    }
}
//Either use the injector directly, which works for the test but uses 19mb of RAM on this test and 203mb on Test 3
$injector = Ray\Di\Injector::create([new Module()]);
//or use a compiled injector, which cannot be tested because it always returns the same instance.
$cache = new \Doctrine\Common\Cache\MemcachedCache();
$m = new Memcached();
$m->addServer('localhost', 11211);
$cache->setMemcached($m);
$injector = \Ray\Di\DiCompiler::create($injector, $cache, 'ray', './tmp');
$a = $injector->getInstance('A');
$a1 = $injector->getInstance('A');
if ($a === $a1) {
    throw new Exception('Container returned the same instance');
}
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $injector->getInstance('A');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
 protected function initCache()
 {
     $cacheConfiguration = $this['config']->getCacheConfiguration();
     switch ($cacheConfiguration['driver']['type']) {
         case 'apc':
             $cacheDriver = new \Doctrine\Common\Cache\ApcCache();
             break;
         case 'memcached':
             $memcached = new \Memcached();
             $memcached->addServer($cacheConfiguration['driver']['host'], $cacheConfiguration['driver']['port']);
             $cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
             $cacheDriver->setMemcached($memcached);
             break;
         case 'memcache':
             $memcache = new \Memcache();
             $memcache->connect($cacheConfiguration['driver']['host'], $cacheConfiguration['driver']['port']);
             $cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
             $cacheDriver->setMemcache($memcache);
             break;
         case 'file':
             $cacheDriver = new PhPFileCache(APPLICATION_PATH . '/doctrine-cache', 'txt');
             $this->setCacheDriver($cacheDriver);
             break;
         default:
             $cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
             break;
     }
     if (isset($cacheConfiguration['driver']['prefix'])) {
         $cacheDriver->setNamespace($cacheConfiguration['driver']['prefix'] . '_');
     }
     $this->setCacheDriver($cacheDriver);
 }
Ejemplo n.º 9
0
 private static function getMemcachedObject()
 {
     if (!defined('__CA_MEMCACHED_HOST__')) {
         define('__CA_MEMCACHED_HOST__', 'localhost');
     }
     if (!defined('__CA_MEMCACHED_PORT__')) {
         define('__CA_MEMCACHED_PORT__', 11211);
     }
     $o_memcached = new Memcached();
     $o_memcached->addServer(__CA_MEMCACHED_HOST__, __CA_MEMCACHED_PORT__);
     $o_cache = new \Doctrine\Common\Cache\MemcachedCache();
     $o_cache->setMemcached($o_memcached);
     return $o_cache;
 }
Ejemplo n.º 10
0
 /**
  * Creates an instance of a doctrine cache provider and assigns it an ID.
  *
  * @param string               $id             - Instance ID.
  * @param string|CacheProvider $typeOrInstance - Instance type.
  * @param array                $config         - Instance config.
  * @param bool                 $refresh        - Re-create the instance even if it's already created.
  *
  * @throws InvalidTypeException
  * @throws InvalidConfigException
  * @throws MissingExtensionException
  *
  * @return CacheProvider
  */
 public function create($id, $typeOrInstance, array $config = [], $refresh = false)
 {
     if (!is_string($id)) {
         throw new \InvalidArgumentException('Argument $id must be a string.');
     }
     if (!is_string($id) && (!is_object($typeOrInstance) || !$typeOrInstance instanceof CacheProvider)) {
         throw new \InvalidArgumentException('Argument $typeOrInstance must be a string or an instance of \\Doctrine\\Common\\Cache\\CacheProvider.');
     }
     if (!isset($this->_instances[$id]) || $refresh) {
         if (is_object($typeOrInstance)) {
             $this->_instances[$id] = $typeOrInstance;
         } else {
             $cache = null;
             switch ($typeOrInstance) {
                 case self::TYPE_APCU:
                     if (!function_exists('apcu_fetch')) {
                         throw MissingExtensionException::create('apcu', 'ApcuCache');
                     }
                     $cache = new \Doctrine\Common\Cache\ApcuCache();
                     break;
                 case self::TYPE_ARRAY:
                     $cache = new \Doctrine\Common\Cache\ArrayCache();
                     break;
                 case self::TYPE_COUCHBASE:
                     if (!class_exists('\\Couchbase')) {
                         throw MissingExtensionException::create('couchbase', 'CouchbaseCache');
                     }
                     $config = array_merge(['couchbase' => null], $config);
                     if (!is_object($config['couchbase']) || !$config['couchbase'] instanceof \Couchbase) {
                         throw InvalidConfigException::create('couchbase', 'an instance of \\Couchbase.');
                     }
                     $cache = new \Doctrine\Common\Cache\CouchbaseCache();
                     $cache->setCouchbase($config['couchbase']);
                     break;
                 case self::TYPE_FILESYSTEM:
                     $config = array_merge(['directory' => null, 'extension' => FilesystemCache::EXTENSION, 'umask' => 02], $config);
                     $cache = new FilesystemCache($config['directory'], $config['extension'], $config['umask']);
                     break;
                 case self::TYPE_MEMCACHE:
                     if (!class_exists('\\Memcache')) {
                         throw MissingExtensionException::create('memcache', 'MemcacheCache');
                     }
                     $config = array_merge(['memcache' => null], $config);
                     if (!is_object($config['memcache']) || !$config['memcache'] instanceof \Memcache) {
                         throw InvalidConfigException::create('memcache', 'an instance of \\Memcache.');
                     }
                     $cache = new \Doctrine\Common\Cache\MemcacheCache();
                     $cache->setMemcache($config['memcache']);
                     break;
                 case self::TYPE_MEMCACHED:
                     if (!class_exists('\\Memcached')) {
                         throw MissingExtensionException::create('memcached', 'MemcachedCache');
                     }
                     $config = array_merge(['memcached' => null], $config);
                     if (!is_object($config['memcached']) || !$config['memcached'] instanceof \Memcached) {
                         throw InvalidConfigException::create('memcached', 'an instance of \\Memcached.');
                     }
                     $cache = new \Doctrine\Common\Cache\MemcachedCache();
                     $cache->setMemcached($config['memcached']);
                     break;
                 case self::TYPE_MONGODB:
                     if (!class_exists('\\MongoCollection')) {
                         throw MissingExtensionException::create('mongo', 'MongoDBCache');
                     }
                     $config = array_merge(['mongoCollection' => null], $config);
                     if (!is_object($config['mongoCollection']) || !$config['mongoCollection'] instanceof \MongoCollection) {
                         throw InvalidConfigException::create('mongoCollection', 'an instance of \\MongoCollection.');
                     }
                     $cache = new \Doctrine\Common\Cache\MongoDBCache($config['mongoCollection']);
                     break;
                 case self::TYPE_PHP_FILE:
                     $config = array_merge(['directory' => null, 'extension' => PhpFileCache::EXTENSION, 'umask' => 02], $config);
                     $cache = new PhpFileCache($config['directory'], $config['extension'], $config['umask']);
                     break;
                 case self::TYPE_PREDIS:
                     if (!class_exists('\\Predis\\ClientInterface')) {
                         throw MissingExtensionException::create('predis', 'PredisCache');
                     }
                     $config = array_merge(['predisClient' => null], $config);
                     if (!is_object($config['predisClient']) || !$config['predisClient'] instanceof \Predis\ClientInterface) {
                         throw InvalidConfigException::create('predisClient', 'an instance of \\Predis\\ClientInterface.');
                     }
                     $cache = new \Doctrine\Common\Cache\PredisCache($config['predisClient']);
                     break;
                 case self::TYPE_REDIS:
                     if (!class_exists('\\Redis')) {
                         throw MissingExtensionException::create('redis', 'RedisCache');
                     }
                     $config = array_merge(['redis' => null], $config);
                     if (!is_object($config['redis']) || !$config['redis'] instanceof \Redis) {
                         throw InvalidConfigException::create('redis', 'an instance of \\Redis.');
                     }
                     $cache = new \Doctrine\Common\Cache\RedisCache();
                     $cache->setRedis($config['redis']);
                     break;
                 case self::TYPE_RIAK:
                     if (!class_exists('\\Riak\\Bucket')) {
                         throw MissingExtensionException::create('riak', 'RiakCache');
                     }
                     $config = array_merge(['riakBucket' => null], $config);
                     if (!is_object($config['riakBucket']) || !$config['riakBucket'] instanceof \Riak\Bucket) {
                         throw InvalidConfigException::create('riakBucket', 'an instance of \\Riak\\Bucket.');
                     }
                     $cache = new \Doctrine\Common\Cache\RiakCache($config['riakBucket']);
                     break;
                 case self::TYPE_SQLITE3:
                     if (!class_exists('\\SQLite3')) {
                         throw MissingExtensionException::create('sqlite3', 'SQLite3Cache');
                     }
                     $config = array_merge(['sqlite3' => null, 'sqlite3Table' => null], $config);
                     if (!is_object($config['sqlite3']) || !$config['sqlite3'] instanceof \SQLite3) {
                         throw InvalidConfigException::create('sqlite3', 'an instance of \\SQLite3.');
                     }
                     if (!is_string($config['sqlite3Table']) || $config['sqlite3Table'] === '') {
                         throw InvalidConfigException::create('sqlite3Table', 'a non-empty string.');
                     }
                     $cache = new \Doctrine\Common\Cache\SQLite3Cache($config['sqlite3'], $config['sqlite3Table']);
                     break;
                 case self::TYPE_VOID:
                     $cache = new VoidCache();
                     break;
                 case self::TYPE_WINCACHE:
                     if (!function_exists('wincache_ucache_get')) {
                         throw MissingExtensionException::create('wincache', 'WinCacheCache');
                     }
                     $cache = new \Doctrine\Common\Cache\WinCacheCache();
                     break;
                 case self::TYPE_XCACHE:
                     if (!function_exists('xcache_isset')) {
                         throw MissingExtensionException::create('xcache', 'XcacheCache');
                     }
                     $cache = new \Doctrine\Common\Cache\XcacheCache();
                     break;
                 case self::TYPE_ZEND_DATA:
                     if (!function_exists('zend_shm_cache_fetch')) {
                         throw new \RuntimeException('Zend Data component must be installed and available before using this Cache Driver.');
                     }
                     $cache = new \Doctrine\Common\Cache\ZendDataCache();
                     break;
                 default:
                     throw InvalidTypeException::create($typeOrInstance);
             }
             $this->_instances[$id] = $cache;
         }
     }
     return $this->_instances[$id];
 }
 public function initModules()
 {
     $this->register(new ConsoleServiceProvider(), array('console.name' => 'AnyContent CMCK Console', 'console.version' => '1.0.0', 'console.project_directory' => APPLICATION_PATH));
     foreach ($this->modules as $module) {
         $class = $module['class'] . '\\Module';
         $o = new $class();
         $o->init($this, $module['options']);
         $module['module'] = $o;
         $this->modules[$module['class']] = $module;
     }
     $this->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => array_reverse($this->templatesFolder)));
     $this['twig']->setCache(APPLICATION_PATH . '/twig-cache');
     // Init Cache
     $cacheConfiguration = $this['config']->getCacheConfiguration();
     switch ($cacheConfiguration['driver']['type']) {
         case 'none':
             $cacheDriver = new ArrayCache();
             break;
         case 'apc':
             $cacheDriver = new \Doctrine\Common\Cache\ApcCache();
             $this->setCacheDriver($cacheDriver);
             break;
         case 'memcached':
             $memcached = new \Memcached();
             $memcached->addServer($cacheConfiguration['driver']['host'], $cacheConfiguration['driver']['port']);
             $memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, 1);
             if (array_key_exists('username', $cacheConfiguration['driver'])) {
                 $memcached->setSaslAuthData($cacheConfiguration['driver']['username'], $cacheConfiguration['driver']['password']);
             }
             $cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
             $cacheDriver->setMemcached($memcached);
             $this->setCacheDriver($cacheDriver);
             break;
         case 'file':
             $cacheDriver = new PhPFileCache(APPLICATION_PATH . '/doctrine-cache', 'txt');
             $this->setCacheDriver($cacheDriver);
             break;
         case 'mysql':
             $cacheDriver = new MySQLCache($cacheConfiguration['driver']['host'], $cacheConfiguration['driver']['dbname'], $cacheConfiguration['driver']['tablename'], $cacheConfiguration['driver']['user'], $cacheConfiguration['driver']['password'], $cacheConfiguration['driver']['port']);
             $this->setCacheDriver($cacheDriver);
             break;
         default:
             throw new \Exception('Unknown authentication adapter type ' . $cacheConfiguration['driver']['type'] . '.');
             break;
     }
     $client = $this->getClient();
     $client->setCacheProvider($cacheDriver);
     // Now add the repositories
     $this->getRepositoryManager()->init();
     // Then run all modules
     foreach ($this->modules as $module) {
         $module['module']->run($this);
     }
     $this['repos']->setUserInfo($this['user']->getClientUserInfo());
 }
Ejemplo n.º 12
0
 /**
  * @return \Doctrine\Common\Cache\CacheProvider
  */
 protected function getCacheDriver()
 {
     if ($this->getParameter('app.devmode')) {
         return new \Doctrine\Common\Cache\ArrayCache();
     }
     if (!$this->hasParameter('cache.host')) {
         return new \Doctrine\Common\Cache\ApcCache();
     }
     $memcached = new \Memcached();
     $memcached->addServer($this->getParameter('cache.host'), $this->getParameter('cache.port'));
     $cache = new \Doctrine\Common\Cache\MemcachedCache();
     $cache->setMemcached($memcached);
     return $cache;
 }
 private function buildCacheFromConfig($config)
 {
     $caches = [];
     if ($config['array']['enabled']) {
         $caches[] = new ArrayCache();
     }
     if ($config['memcached']['enabled']) {
         $memcached = new \Memcached();
         if (!$memcached->addServer($config['memcached']['host'], $config['memcached']['port'])) {
             throw new RuntimeException('Fail to connect to Memcached');
         }
         $memcachedCache = new \Doctrine\Common\Cache\MemcachedCache();
         $memcachedCache->setMemcached($memcached);
         $caches[] = $memcachedCache;
     }
     switch (count($caches)) {
         case 0:
             return null;
         case 1:
             return reset($caches);
         default:
             return new ChainCache($caches);
     }
 }