public function testGetModules()
 {
     $modules = [new ModuleMock1(), new ModuleMock2()];
     $modulesLoader = $this->provideModulesLoader($modules);
     $driver = new FileSystem();
     $driver->setOptions(['path' => __DIR__ . '/stash']);
     $driver->clear();
     $proxy = new ModulesLoaderProxy($modulesLoader, new Pool($driver));
     $this->assertEquals($modules, $proxy->getModules());
     $proxy = new ModulesLoaderProxy($modulesLoader, new Pool($driver));
     $this->assertEquals($modules, $proxy->getModules());
     $driver->clear();
 }
예제 #2
0
 protected function createPool()
 {
     $cache_driver = tpenv('TP_CACHE_DRIVER', 'file');
     switch ($cache_driver) {
         case 'redis':
             $driver = new Stash\Driver\Redis();
             $server = Config::get('database.redis.default.host');
             $port = Config::get('database.redis.default.port');
             $database = Config::get('database.redis.default.database');
             TPLog::debug('Server Config: ', ['server' => $server, 'port' => $port]);
             $driver->setOptions(['servers' => [[$server, $port]], 'database' => $database]);
             break;
         default:
             $driver = new Stash\Driver\FileSystem();
             $driver->setOptions(['path' => $this->storagePath() . '/framework/cache/stash']);
     }
     $this->pool = new Stash\Pool($driver);
 }
 /**
  * Returns cache settings based on which cache functionality is available on the current server
  *
  * Order of preference:
  * - FileSystem
  * - APC
  * - Memcache  [DISABLED, SEE INLINE]
  * - Xcache  [DISABLED, SEE INLINE]
  * - variable instance cache  [DISABLED, SEE INLINE]
  *
  * @return array
  */
 protected function getStashCacheSettings()
 {
     // Should only contain one out of the box
     $handlers = array();
     $inMemory = false;
     $handlerSetting = array();
     if (FileSystemDriver::isAvailable()) {
         $handlers[] = 'FileSystem';
         $inMemory = true;
         // If running on Windows, use "crc32" keyHashFunction
         if (stripos(php_uname(), 'win') === 0) {
             $handlerSetting['FileSystem'] = array('keyHashFunction' => 'crc32');
         }
     } else {
         // '/dev/null' fallback driver, no cache at all
         $handlers[] = 'BlackHole';
         $inMemory = true;
     }
     return array('caches' => array('default' => array('drivers' => $handlers, 'inMemory' => $inMemory, 'registerDoctrineAdapter' => false) + $handlerSetting));
 }
 /**
  * Test creation of file with long paths (Windows issue)
  *
  * Regression test for https://github.com/tedivm/Stash/issues/61
  *
  * There are currently no short term plans to allow long paths in PHP windows
  * http://www.mail-archive.com/internals@lists.php.net/msg62672.html
  *
  */
 public function testLongPathFileCreation()
 {
     if (strtolower(substr(PHP_OS, 0, 3)) !== 'win') {
         $this->markTestSkipped('This test can only occur on Windows based systems.');
     }
     $cachePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'stash';
     $driver = new FileSystem();
     $driver->setOptions(array('keyHashFunction' => 'Stash\\Test\\Driver\\strdup', 'path' => $cachePath, 'dirSplit' => 1));
     $key = array();
     // MAX_PATH is 260 - http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
     while (strlen($cachePath . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $key)) < 259) {
         // 32 character string typical of an md5 sum
         $key[] = "abcdefghijklmnopqrstuvwxyz123456";
     }
     $this->expiration = time() + 3600;
     $this->setExpectedException('\\Stash\\Exception\\WindowsPathMaxLengthException');
     $driver->storeData($key, "test", $this->expiration);
 }
예제 #5
0
 /**
  * Builds cache pool instance.
  *
  * @todo Most likely the factory should return Ephemeral cache if a real
  * storage cannot be used by some resons.
  *
  * @return PoolInterface An instance of cache pool.
  * @throws \RuntimeException If at least one of factory's options is
  * invalid.
  */
 public function getCache()
 {
     if (is_null($this->cache)) {
         $storage = $this->getOption('storage');
         if ($storage === 'none') {
             $driver = new EphemeralDriver();
         } elseif ($storage === 'file_system') {
             $driver = new FileSystemDriver();
             $driver->setOptions(array('path' => $this->getOption('path')));
         } elseif ($storage === 'memcached') {
             $servers = $this->getOption('memcached_servers');
             // Make sure memcached servers was described correctly. The next
             // statement will throw Exception if something is wrong so we do
             // not need to check the result.
             $this->validateMemcachedServers($servers);
             // Convert structure from the "memcached_servers" option to the
             // form used in cache driver.
             $formated_servers = array_map(function ($server) {
                 return array($server['host'], intval($server['port']), isset($server['weight']) ? intval($server['weight']) : 0);
             }, $servers);
             $driver = new MemcacheDriver();
             $driver->setOptions(array('servers' => $formated_servers, 'extension' => 'memcached'));
         } else {
             throw new \RuntimeException(sprintf('Wrong value of "storage" option: "%s"', $storage));
         }
         $this->cache = new CachePool($driver);
     }
     return $this->cache;
 }