/** * Execute this configuration handler. * * @param string An absolute filesystem path to a configuration file. * @param string An optional context in which we are currently running. * * @return string Data to be written to a cache file. * * @throws <b>AgaviUnreadableException</b> If a requested configuration * file does not exist or is not * readable. * @throws <b>AgaviParseException</b> If a requested configuration file is * improperly formatted. * * @author Dominik del Bondio <*****@*****.**> * @since 0.11.0 */ public function execute($config, $context = null) { $pathParts = pathinfo($config); // unlike basename, filename does not contain the extension, which is what we need there $lookupPaths = AgaviLocale::getLookupPath($pathParts['filename']); $lookupPaths[] = 'root'; $data = array('layout' => array('orientation' => array('lines' => 'top-to-bottom', 'characters' => 'left-to-right'))); foreach (array_reverse($lookupPaths) as $basename) { $filePath = $pathParts['dirname'] . '/' . $basename . '.' . $pathParts['extension']; if (is_readable($filePath)) { $ldmlTree = AgaviConfigCache::parseConfig($filePath, false, $this->getValidationFile(), $this->parser); $this->prepareParentInformation($ldmlTree); $this->parseLdmlTree($ldmlTree->ldml, $data); } } $dayMap = array('sun' => AgaviDateDefinitions::SUNDAY, 'mon' => AgaviDateDefinitions::MONDAY, 'tue' => AgaviDateDefinitions::TUESDAY, 'wed' => AgaviDateDefinitions::WEDNESDAY, 'thu' => AgaviDateDefinitions::THURSDAY, 'fri' => AgaviDateDefinitions::FRIDAY, 'sat' => AgaviDateDefinitions::SATURDAY); // fix the day indices for all day fields foreach ($data['calendars'] as $calKey => &$calValue) { // skip the 'default' => '' key => value pair if (is_array($calValue)) { if (isset($calValue['days']['format'])) { foreach ($calValue['days']['format'] as $formatKey => &$formatValue) { if (is_array($formatValue)) { $newData = array(); foreach ($formatValue as $day => $value) { $newData[$dayMap[$day]] = $value; } $formatValue = $newData; } } } if (isset($calValue['days']['stand-alone'])) { foreach ($calValue['days']['stand-alone'] as $formatKey => &$formatValue) { if (is_array($formatValue)) { $newData = array(); foreach ($formatValue as $day => $value) { $newData[$dayMap[$day]] = $value; } $formatValue = $newData; } } } } } $code = array(); $code[] = 'return ' . var_export($data, true) . ';'; return $this->generate($code, $config); }
/** * @see AgaviIniConfigHandler::execute() * * @author David Zülke <*****@*****.**> * @since 0.10.0 */ public function execute($config, $context = null) { $parsed = AgaviConfigCache::parseConfig($config, false, $this->getValidationFile(), $this->parser); if (!isset($parsed->configurations)) { $error = 'Configuration file "%s" is not in the Agavi 0.11 legacy namespace (http://agavi.org/agavi/1.0/config) and/or does not contain a <configurations> element as root node.'; $error = sprintf($error, $config); throw new AgaviConfigurationException($error); } $configurations = $this->orderConfigurations($parsed->configurations, AgaviConfig::get('core.environment'), $context); $data = array(); foreach ($configurations as $cfg) { $data = array_merge($data, $this->convertToArray($cfg, true)); } // compile data $code = 'return ' . var_export($data, true) . ';'; return $this->generate($code, $config); }
/** * Returns a properly ordered array of AgaviConfigValueHolder configuration * elements for given env and context. * * @param AgaviConfigValueHolder The root config element * @param string An environment name. * @param string A context name. * @param bool Whether the parser class should be * autoloaded or not. * * @return array An array of ConfigValueHolder configuration elements. * * @author David Zülke <*****@*****.**> * @since 0.11.0 */ public function orderConfigurations(AgaviConfigValueHolder $configurations, $environment = null, $context = null, $autoloadParser = true) { $configs = array(); if ($configurations->hasAttribute('parent')) { $parent = AgaviToolkit::literalize($configurations->getAttribute('parent')); $parentConfigs = $this->orderConfigurations(AgaviConfigCache::parseConfig($parent, $autoloadParser, $this->getValidationFile(), $this->parser)->configurations, $environment, $context, $autoloadParser); $configs = array_merge($configs, $parentConfigs); } foreach ($configurations as $cfg) { if (!$cfg->hasAttribute('environment') && !$cfg->hasAttribute('context')) { $configs[] = $cfg; } } foreach ($configurations as $cfg) { if ($environment !== null && $cfg->hasAttribute('environment') && self::testPattern($cfg->getAttribute('environment'), $environment) && !$cfg->hasAttribute('context')) { $configs[] = $cfg; } } foreach ($configurations as $cfg) { if (!$cfg->hasAttribute('environment') && $context !== null && $cfg->hasAttribute('context') && self::testPattern($cfg->getAttribute('context'), $context)) { $configs[] = $cfg; } } foreach ($configurations as $cfg) { if ($environment !== null && $cfg->hasAttribute('environment') && self::testPattern($cfg->getAttribute('environment'), $environment) && $context !== null && $cfg->hasAttribute('context') && self::testPattern($cfg->getAttribute('context'), $context)) { $configs[] = $cfg; } } return $configs; }