/** * {@inheritdoc} */ public static function configure(\Pimple $app, $appPath, $libPath, $env = '', $user = '', $sapi = '', $cache = false) { $configCacheHash = $cache ? implode('.', array($appPath, $libPath, $env, $user, $sapi)) : ''; $config = $cache ? Generic::getConfigCache($configCacheHash) : false; if (!$config) { //@TODO: allow not just json to be loaded $configPath = realpath(sprintf('%s/config/user/%s.json', $appPath, $user)); if (!$configPath) { $configPath = realpath(sprintf('%s/config/env/%s.json', $appPath, $env)); if (!$configPath) { $configPath = realpath(sprintf('%s/config/app.json', $appPath, $sapi)); } } $config = array('core' => array('user' => $user, 'env' => $env, 'sapi' => $sapi, 'appPath' => $appPath, 'libPath' => $libPath, 'configPath' => $configPath)); if (file_exists($configPath)) { $loadedConfig = Config::load($configPath, $config['core']); $loadedConfig['core'] = array_merge($loadedConfig['core'], $config['core']); $config = $loadedConfig; } if ($cache) { Generic::setConfigCache($configCacheHash, $config); } else { Generic::clearConfigCache(); } } Config::configurePimple($app, $config); return $config; }
public function testApplicationConfigCache() { if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) { $this->markTestSkipped('The ' . __CLASS__ . ' requires apc extension with apc.enable_cli=1.'); } $this->assertFalse(apc_exists(Generic::CACHE_KEY)); $configHash = 'fake-hash'; $config = array('variables'); Generic::setConfigCache($configHash, $config); $this->assertTrue(apc_exists(Generic::CACHE_KEY)); $cacheConfig = Generic::getConfigCache($configHash); $this->assertInternalType('array', $cacheConfig); $this->assertEquals($config[0], $cacheConfig[0]); Generic::clearConfigCache(); $this->assertFalse(apc_exists(Generic::CACHE_KEY)); Generic::setConfigCache($configHash, $config); $this->assertNull(Generic::getConfigCache('incorrect-fake-hash')); $this->assertFalse(apc_exists(Generic::CACHE_KEY)); }