/** * 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(array(), $constants); foreach ($config as $section => $values) { if (strpos($section, '_') === false) { // extension section $AssetConfig->addExtension($section, $values); } elseif (strpos($section, self::FILTER_PREFIX) === 0) { // filter section. $name = str_replace(self::FILTER_PREFIX, '', $section); $AssetConfig->filterConfig($name, $values); } else { list($extension, $key) = explode('_', $section, 2); // must be a build target. $files = isset($values['files']) ? $values['files'] : array(); $filters = isset($values['filters']) ? $values['filters'] : array(); $AssetConfig->addTarget($key, $files, $filters); } } if (!empty($config['General']['cacheConfig'])) { Cache::write(self::CACHE_ASSET_CONFIG_KEY, $AssetConfig, self::CACHE_CONFIG); } return $AssetConfig; }
/** * 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); } } }