public function testIsFreshConfigExpire()
 {
     touch(TMP . '/libs.js');
     $data = parse_ini_file($this->testConfig, true);
     $constants = array('TEST_FILES' => $this->_testFiles);
     $config = new AssetConfig($data, $constants, strtotime('-1 minute'));
     $config->cachePath('js', TMP);
     $config->set('js.timestamp', false);
     $cache = new AssetCache($config);
     $this->assertTrue($cache->isFresh('libs.js'));
     $config = new AssetConfig($data, $constants, strtotime('+1 minute'));
     $config->cachePath('js', TMP);
     $config->set('js.timestamp', false);
     $cache = new AssetCache($config);
     $this->assertFalse($cache->isFresh('libs.js'));
     unlink(TMP . '/libs.js');
 }
Esempio n. 2
0
 /**
  * Transforms the config data into a more structured form
  *
  * @param array $contents Contents to build a config object from.
  * @return AssetConfig
  */
 protected static function _parseConfig($config, $constants)
 {
     $AssetConfig = new AssetConfig(self::$_defaults, $constants);
     foreach ($config as $section => $values) {
         if (in_array($section, self::$_extensionTypes)) {
             // extension section, merge in the defaults.
             $defaults = $AssetConfig->get($section);
             if ($defaults) {
                 $values = array_merge($defaults, $values);
             }
             $AssetConfig->addExtension($section, $values);
         } elseif (strtolower($section) === self::GENERAL) {
             $AssetConfig->set(self::GENERAL, $values);
         } elseif (strpos($section, self::FILTER_PREFIX) === 0) {
             // filter section.
             $name = str_replace(self::FILTER_PREFIX, '', $section);
             $AssetConfig->filterConfig($name, $values);
         } else {
             $lastDot = strrpos($section, '.') + 1;
             $extension = substr($section, $lastDot);
             $key = $section;
             // Is there a prefix? Chop it off.
             if (strpos($section, $extension . '_') !== false) {
                 $key = substr($key, strlen($extension) + 1);
             }
             // must be a build target.
             $AssetConfig->addTarget($key, $values);
         }
     }
     if ($AssetConfig->general('cacheConfig')) {
         Cache::write(self::CACHE_ASSET_CONFIG_KEY, $AssetConfig, self::CACHE_CONFIG);
     }
     return $AssetConfig;
 }
 /**
  * Reads a config file and applies it to the given config instance
  *
  * @param string $iniFile Contents to apply to the config instance.
  * @param AssetConfig $AssetConfig The config instance instance we're applying this config file to.
  * @param string $prefix Prefix for the target key
  */
 protected static function _parseConfigFile($iniFile, $AssetConfig, $prefix = '')
 {
     $config = self::_readConfig($iniFile);
     foreach ($config as $section => $values) {
         if (in_array($section, self::$_extensionTypes)) {
             // extension section, merge in the defaults.
             $defaults = $AssetConfig->get($section);
             if ($defaults) {
                 $values = array_merge($defaults, $values);
             }
             $AssetConfig->addExtension($section, $values);
         } elseif (strtolower($section) === self::GENERAL) {
             $AssetConfig->set(self::GENERAL, $values);
         } elseif (strpos($section, self::FILTER_PREFIX) === 0) {
             // filter section.
             $name = str_replace(self::FILTER_PREFIX, '', $section);
             $AssetConfig->filterConfig($name, $values);
         } else {
             $lastDot = strrpos($section, '.') + 1;
             $extension = substr($section, $lastDot);
             $key = $section;
             // Is there a prefix? Chop it off.
             if (strpos($section, $extension . '_') !== false) {
                 $key = substr($key, strlen($extension) + 1);
             }
             // must be a build target.
             $AssetConfig->addTarget($prefix . $key, $values);
         }
     }
 }