/**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'suite');
     // remember the config file path
     $config = $document->documentURI;
     $data = array();
     // loop over <configuration> elements
     foreach ($document->getConfigurationElements() as $configuration) {
         foreach ($configuration->get('suites') as $current) {
             $includes = array();
             foreach ($current->get('includes') as $include) {
                 $includes[] = $include->textContent;
             }
             $excludes = array();
             foreach ($current->get('excludes') as $exclude) {
                 $excludes[] = $exclude->textContent;
             }
             $suite = array('class' => $current->getAttribute('class', 'AgaviTestSuite'), 'base' => $current->getAttribute('base', 'tests/'), 'includes' => $includes, 'excludes' => $excludes);
             $suite['testfiles'] = array();
             foreach ($current->get('testfiles') as $file) {
                 $suite['testfiles'][] = $file->textContent;
             }
             $data[$current->getAttribute('name')] = $suite;
         }
     }
     $code = 'return ' . var_export($data, true);
     return $this->generate($code, $config);
 }
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $data = array();
     $prefix = "org.icinga.";
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'settings');
     foreach ($document->getConfigurationElements() as $cfg) {
         foreach ($cfg->get('settings') as $setting) {
             $localPrefix = $prefix;
             // let's see if this buddy has a <settings> parent with valuable information
             if ($setting->parentNode->localName == 'settings') {
                 if ($setting->parentNode->hasAttribute('prefix')) {
                     $localPrefix = $setting->parentNode->getAttribute('prefix');
                 }
             }
             $settingName = $localPrefix . $setting->getAttribute('name');
             if ($setting->hasAgaviParameters()) {
                 $data[$settingName] = $setting->getAgaviParameters();
             } else {
                 $data[$settingName] = AgaviToolkit::literalize($setting->getValue());
             }
         }
     }
     $code = 'AgaviConfig::fromArray(' . var_export($data, true) . ');';
     return $this->generate($code, $document->documentURI);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'compile');
     $config = $document->documentURI;
     $data = array();
     // let's do our fancy work
     foreach ($document->getConfigurationElements() as $configuration) {
         if (!$configuration->has('compiles')) {
             continue;
         }
         foreach ($configuration->get('compiles') as $compileFile) {
             $file = trim($compileFile->getValue());
             $file = AgaviToolkit::expandDirectives($file);
             $file = self::replacePath($file);
             $file = realpath($file);
             if (!is_readable($file)) {
                 // file doesn't exist
                 $error = 'Configuration file "%s" specifies nonexistent ' . 'or unreadable file "%s"';
                 $error = sprintf($error, $config, $compileFile->getValue());
                 throw new AgaviParseException($error);
             }
             if (AgaviConfig::get('core.debug', false)) {
                 // debug mode, just require() the files, makes for nicer stack traces
                 $contents = 'require(' . var_export($file, true) . ');';
             } else {
                 // no debug mode, so make things fast
                 $contents = $this->formatFile(file_get_contents($file));
             }
             // append file data
             $data[$file] = $contents;
         }
     }
     return $this->generate($data, $config);
 }
 /**
  * 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     Uwe Mesecke <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'validators');
     $config = $document->documentURI;
     $classMap = array();
     $code = array();
     //array('lines' => array(), 'order' => array());
     foreach ($document->getConfigurationElements() as $cfg) {
         if ($cfg->has('validator_definitions')) {
             foreach ($cfg->get('validator_definitions') as $def) {
                 $name = $def->getAttribute('name');
                 if (!isset($this->classMap[$name])) {
                     $this->classMap[$name] = array('class' => $def->getAttribute('class'), 'parameters' => array());
                 }
                 $this->classMap[$name]['class'] = $def->getAttribute('class', $this->classMap[$name]['class']);
                 $this->classMap[$name]['parameters'] = $def->getAgaviParameters($this->classMap[$name]['parameters']);
             }
         }
         $code = $this->processValidatorElements($cfg, $code, 'validationManager');
     }
     $newCode = array();
     if (isset($code[''])) {
         $newCode = $code[''];
         unset($code['']);
     }
     foreach ($code as $method => $codes) {
         $newCode[] = 'if($method == ' . var_export($method, true) . ') {';
         foreach ($codes as $line) {
             $newCode[] = $line;
         }
         $newCode[] = '}';
     }
     return $this->generate($newCode, $config);
 }
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $this->document = $document;
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'ic');
     $this->setupXPath();
     $this->fetchParameters();
     $commands = $this->fetchCommands();
     return $this->generate('return ' . var_export($commands, true));
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     Noah Fontes <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'databases');
     $databases = array();
     $default = null;
     foreach ($document->getConfigurationElements() as $configuration) {
         if (!$configuration->hasChildren('databases')) {
             continue;
         }
         $databasesElement = $configuration->getChild('databases');
         // make sure we have a default database exists
         if (!$databasesElement->hasAttribute('default') && $default === null) {
             // missing default database
             $error = 'Configuration file "%s" must specify a default database configuration';
             $error = sprintf($error, $document->documentURI);
             throw new AgaviParseException($error);
         }
         if ($databasesElement->hasAttribute('default')) {
             $default = $databasesElement->getAttribute('default');
         }
         // let's do our fancy work
         foreach ($configuration->get('databases') as $database) {
             $name = $database->getAttribute('name');
             if (!isset($databases[$name])) {
                 $databases[$name] = array('parameters' => array());
                 if (!$database->hasAttribute('class')) {
                     $error = 'Configuration file "%s" specifies database "%s" with missing class key';
                     $error = sprintf($error, $document->documentURI, $name);
                     throw new AgaviParseException($error);
                 }
             }
             $databases[$name]['class'] = $database->hasAttribute('class') ? $database->getAttribute('class') : $databases[$name]['class'];
             $databases[$name]['parameters'] = $database->getAgaviParameters($databases[$name]['parameters']);
         }
     }
     if (!$databases) {
         // we have no connections
         $error = 'Configuration file "%s" does not contain any database connections.';
         $error = sprintf($error, $document->documentURI);
         throw new AgaviConfigurationException($error);
     }
     $data = array();
     foreach ($databases as $name => $db) {
         // append new data
         $data[] = sprintf('$database = new %s();', $db['class']);
         $data[] = sprintf('$this->databases[%s] = $database;', var_export($name, true));
         $data[] = sprintf('$database->initialize($this, %s);', var_export($db['parameters'], true));
     }
     if (!isset($databases[$default])) {
         $error = 'Configuration file "%s" specifies undefined default database "%s".';
         $error = sprintf($error, $document->documentURI, $default);
         throw new AgaviConfigurationException($error);
     }
     $data[] = sprintf('$this->defaultDatabaseName = %s;', var_export($default, true));
     return $this->generate($data, $document->documentURI);
 }
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $this->document = $document;
     $this->menuDefinition = new AppKitLinkedList();
     $this->context = AgaviContext::getInstance();
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'm');
     $this->setupXPath();
     $this->fetchMenudefinition();
     return $this->generate('return ' . var_export($this->menuDefinition->toArray(), true));
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $document->setDefaultNamespace($this->getParameter('namespace_uri', ''));
     $data = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         $data = array_merge($data, $this->convertToArray($cfg, true));
     }
     // compile data
     $code = 'return ' . var_export($data, true) . ';';
     return $this->generate($code, $document->documentURI);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'translation');
     $config = $document->documentURI;
     $translatorData = array();
     $localeData = array();
     $defaultDomain = '';
     $defaultLocale = null;
     $defaultTimeZone = null;
     foreach ($document->getConfigurationElements() as $cfg) {
         if ($cfg->hasChild('available_locales')) {
             $availableLocales = $cfg->getChild('available_locales');
             // TODO: is this really optional? according to the schema: yes...
             $defaultLocale = $availableLocales->getAttribute('default_locale', $defaultLocale);
             $defaultTimeZone = $availableLocales->getAttribute('default_timezone', $defaultTimeZone);
             foreach ($availableLocales as $locale) {
                 $name = $locale->getAttribute('identifier');
                 if (!isset($localeData[$name])) {
                     $localeData[$name] = array('name' => $name, 'params' => array(), 'fallback' => null, 'ldml_file' => null);
                 }
                 $localeData[$name]['params'] = $locale->getAgaviParameters($localeData[$name]['params']);
                 $localeData[$name]['fallback'] = $locale->getAttribute('fallback', $localeData[$name]['fallback']);
                 $localeData[$name]['ldml_file'] = $locale->getAttribute('ldml_file', $localeData[$name]['ldml_file']);
             }
         }
         if ($cfg->hasChild('translators')) {
             $translators = $cfg->getChild('translators');
             $defaultDomain = $translators->getAttribute('default_domain', $defaultDomain);
             $this->getTranslators($translators, $translatorData);
         }
     }
     $data = array();
     $data[] = sprintf('$this->defaultDomain = %s;', var_export($defaultDomain, true));
     $data[] = sprintf('$this->defaultLocaleIdentifier = %s;', var_export($defaultLocale, true));
     $data[] = sprintf('$this->defaultTimeZone = %s;', var_export($defaultTimeZone, true));
     foreach ($localeData as $locale) {
         // TODO: fallback stuff
         $data[] = sprintf('$this->availableConfigLocales[%s] = array(\'identifier\' => %s, \'identifierData\' => %s, \'parameters\' => %s);', var_export($locale['name'], true), var_export($locale['name'], true), var_export(AgaviLocale::parseLocaleIdentifier($locale['name']), true), var_export($locale['params'], true));
     }
     foreach ($translatorData as $domain => $translator) {
         foreach (array('msg', 'num', 'cur', 'date') as $type) {
             if (isset($translator[$type]['class'])) {
                 if (!class_exists($translator[$type]['class'])) {
                     throw new AgaviConfigurationException(sprintf('The Translator or Formatter class "%s" for domain "%s" could not be found.', $translator[$type]['class'], $domain));
                 }
                 $data[] = join("\n", array(sprintf('$this->translators[%s][%s] = new %s();', var_export($domain, true), var_export($type, true), $translator[$type]['class']), sprintf('$this->translators[%s][%s]->initialize($this->getContext(), %s);', var_export($domain, true), var_export($type, true), var_export($translator[$type]['params'], true)), sprintf('$this->translatorFilters[%s][%s] = %s;', var_export($domain, true), var_export($type, true), var_export($translator[$type]['filters'], true))));
             }
         }
     }
     return $this->generate($data, $config);
 }
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'cronk');
     $config = $document->documentURI;
     $cronks = array();
     $categories = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         $this->getXmlConfiguration($cfg, 'cronks', 'cronk', $cronks);
         $this->getXmlConfiguration($cfg, 'categories', 'category', $categories);
     }
     $code = 'return ' . var_export(array($cronks, $categories), true);
     return $this->generate($code, $config);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @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     David Zülke <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'settings');
     // init our data array
     $data = array();
     $prefix = 'core.';
     foreach ($document->getConfigurationElements() as $cfg) {
         // let's do our fancy work
         if ($cfg->has('system_actions')) {
             foreach ($cfg->get('system_actions') as $action) {
                 $name = $action->getAttribute('name');
                 $data[sprintf('actions.%s_module', $name)] = $action->getChild('module')->getValue();
                 $data[sprintf('actions.%s_action', $name)] = $action->getChild('action')->getValue();
             }
         }
         // loop over <setting> elements; there can be many of them
         foreach ($cfg->get('settings') as $setting) {
             $localPrefix = $prefix;
             // let's see if this buddy has a <settings> parent with valuable information
             if ($setting->parentNode->localName == 'settings') {
                 if ($setting->parentNode->hasAttribute('prefix')) {
                     $localPrefix = $setting->parentNode->getAttribute('prefix');
                 }
             }
             $settingName = $localPrefix . $setting->getAttribute('name');
             if ($setting->hasAgaviParameters()) {
                 $data[$settingName] = $setting->getAgaviParameters();
             } else {
                 $data[$settingName] = $setting->getLiteralValue();
             }
         }
         if ($cfg->has('exception_templates')) {
             foreach ($cfg->get('exception_templates') as $exception_template) {
                 $tpl = AgaviToolkit::expandDirectives($exception_template->getValue());
                 if (!is_readable($tpl)) {
                     throw new AgaviConfigurationException('Exception template "' . $tpl . '" does not exist or is unreadable');
                 }
                 if ($exception_template->hasAttribute('context')) {
                     foreach (array_map('trim', explode(' ', $exception_template->getAttribute('context'))) as $ctx) {
                         $data['exception.templates.' . $ctx] = $tpl;
                     }
                 } else {
                     $data['exception.default_template'] = AgaviToolkit::expandDirectives($tpl);
                 }
             }
         }
     }
     $code = 'AgaviConfig::fromArray(' . var_export($data, true) . ');';
     return $this->generate($code, $document->documentURI);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @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     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'rbac_definitions');
     $data = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         if (!$cfg->has('roles')) {
             continue;
         }
         $this->parseRoles($cfg->get('roles'), null, $data);
     }
     $code = "return " . var_export($data, true) . ";";
     return $this->generate($code, $document->documentURI);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      <b>AgaviXmlConfigDomDocument</b> The document to parse.
  *
  * @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     Luis Merino <*****@*****.**>
  * @since      0.1.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // setting up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'static_files');
     $routing = $this->context->getRouting();
     $data = array();
     // let's do our fancy work
     foreach ($document->getConfigurationElements() as $cfg) {
         if ($cfg->has('routes')) {
             $this->parseRoutesAndFiles($routing, $cfg->get('routes'), $data);
         }
     }
     $code = sprintf('$this->files = %s;', var_export($data, true));
     return $this->generate($code, $document->documentURI);
 }
Ejemplo n.º 14
0
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'module');
     // remember the config file path
     $config = $document->documentURI;
     $enabled = false;
     $prefix = 'modules.${moduleName}.';
     $data = array();
     // loop over <configuration> elements
     foreach ($document->getConfigurationElements() as $configuration) {
         $module = $configuration->getChild('module');
         if (!$module) {
             continue;
         }
         // enabled flag is treated separately
         $enabled = (bool) AgaviToolkit::literalize($module->getAttribute('enabled'));
         // loop over <setting> elements; there can be many of them
         foreach ($module->get('settings') as $setting) {
             $localPrefix = $prefix;
             // let's see if this buddy has a <settings> parent with valuable information
             if ($setting->parentNode->localName == 'settings') {
                 if ($setting->parentNode->hasAttribute('prefix')) {
                     $localPrefix = $setting->parentNode->getAttribute('prefix');
                 }
             }
             $settingName = $localPrefix . $setting->getAttribute('name');
             if ($setting->hasAgaviParameters()) {
                 $data[$settingName] = $setting->getAgaviParameters();
             } else {
                 $data[$settingName] = AgaviToolkit::literalize($setting->getValue());
             }
         }
     }
     $code = array();
     $code[] = '$lcModuleName = strtolower($moduleName);';
     $code[] = 'AgaviConfig::set(AgaviToolkit::expandVariables(' . var_export($prefix . 'enabled', true) . ', array(\'moduleName\' => $lcModuleName)), ' . var_export($enabled, true) . ', true, true);';
     if (count($data)) {
         $code[] = '$moduleConfig = ' . var_export($data, true) . ';';
         $code[] = '$moduleConfigKeys = array_keys($moduleConfig);';
         $code[] = 'foreach($moduleConfigKeys as &$value) $value = AgaviToolkit::expandVariables($value, array(\'moduleName\' => $lcModuleName));';
         $code[] = '$moduleConfig = array_combine($moduleConfigKeys, $moduleConfig);';
         $code[] = 'AgaviConfig::fromArray($moduleConfig);';
     }
     return $this->generate($code, $config);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to handle.
  *
  * @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 <*****@*****.**>
  * @author     Noah Fontes <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'config_handlers');
     // init our data arrays
     $handlers = array();
     foreach ($document->getConfigurationElements() as $configuration) {
         if (!$configuration->has('handlers')) {
             continue;
         }
         // let's do our fancy work
         foreach ($configuration->get('handlers') as $handler) {
             $pattern = $handler->getAttribute('pattern');
             $category = AgaviToolkit::normalizePath(AgaviToolkit::expandDirectives($pattern));
             $class = $handler->getAttribute('class');
             $transformations = array(AgaviXmlConfigParser::STAGE_SINGLE => array(), AgaviXmlConfigParser::STAGE_COMPILATION => array());
             if ($handler->has('transformations')) {
                 foreach ($handler->get('transformations') as $transformation) {
                     $path = AgaviToolkit::literalize($transformation->getValue());
                     $for = $transformation->getAttribute('for', AgaviXmlConfigParser::STAGE_SINGLE);
                     $transformations[$for][] = $path;
                 }
             }
             $validations = array(AgaviXmlConfigParser::STAGE_SINGLE => array(AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array()), AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array())), AgaviXmlConfigParser::STAGE_COMPILATION => array(AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array()), AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array())));
             if ($handler->has('validations')) {
                 foreach ($handler->get('validations') as $validation) {
                     $path = AgaviToolkit::literalize($validation->getValue());
                     $type = null;
                     if (!$validation->hasAttribute('type')) {
                         $type = $this->guessValidationType($path);
                     } else {
                         $type = $validation->getAttribute('type');
                     }
                     $for = $validation->getAttribute('for', AgaviXmlConfigParser::STAGE_SINGLE);
                     $step = $validation->getAttribute('step', AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER);
                     $validations[$for][$step][$type][] = $path;
                 }
             }
             $handlers[$category] = isset($handlers[$category]) ? $handlers[$category] : array('parameters' => array());
             $handlers[$category] = array('class' => $class, 'parameters' => $handler->getAgaviParameters($handlers[$category]['parameters']), 'transformations' => $transformations, 'validations' => $validations);
         }
     }
     $data = array('return ' . var_export($handlers, true));
     return $this->generate($data, $document->documentURI);
 }
Ejemplo n.º 16
0
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'filters');
     $config = $document->documentURI;
     $filters = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         if ($cfg->has('filters')) {
             foreach ($cfg->get('filters') as $filter) {
                 $name = $filter->getAttribute('name', AgaviToolkit::uniqid());
                 if (!isset($filters[$name])) {
                     $filters[$name] = array('params' => array(), 'enabled' => AgaviToolkit::literalize($filter->getAttribute('enabled', true)));
                 } else {
                     $filters[$name]['enabled'] = AgaviToolkit::literalize($filter->getAttribute('enabled', $filters[$name]['enabled']));
                 }
                 if ($filter->hasAttribute('class')) {
                     $filters[$name]['class'] = $filter->getAttribute('class');
                 }
                 $filters[$name]['params'] = $filter->getAgaviParameters($filters[$name]['params']);
             }
         }
     }
     $data = array();
     foreach ($filters as $name => $filter) {
         if (stripos($name, 'agavi') === 0) {
             throw new AgaviConfigurationException('Filter names must not start with "agavi".');
         }
         if (!isset($filter['class'])) {
             throw new AgaviConfigurationException('No class name specified for filter "' . $name . '" in ' . $config);
         }
         if ($filter['enabled']) {
             $rc = new ReflectionClass($filter['class']);
             $if = 'AgaviI' . ucfirst(strtolower(substr(basename($config), 0, strpos(basename($config), '_filters')))) . 'Filter';
             if (!$rc->implementsInterface($if)) {
                 throw new AgaviFactoryException('Filter "' . $name . '" does not implement interface "' . $if . '"');
             }
             $data[] = '$filter = new ' . $filter['class'] . '();';
             $data[] = '$filter->initialize($this->context, ' . var_export($filter['params'], true) . ');';
             $data[] = '$filters[' . var_export($name, true) . '] = $filter;';
         }
     }
     return $this->generate($data, $config);
 }
 /**
  * Voer de config handler uit.
  *
  * @param   AgaviXmlConfigDomDocument   $document
  * @return  string                      Data die moet weggeschreven worden
  *                                      naar de cache.
  * @throws  AgaviParseException         Indien de xml file niet geldig is.
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // setting up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'gateways');
     $data = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         if (!$cfg->has('gateways')) {
             continue;
         }
         $gateways = $cfg->get('gateways');
         foreach ($gateways as $gateway) {
             $gn = $gateway->getAttribute('name');
             if (!isset($data[$gn])) {
                 $data[$gn] = array();
             }
             $data[$gn] = $gateway->getAgaviParameters($data[$gn]);
         }
     }
     $code = sprintf('$gatewayRegistry = new KVDutil_GatewayRegistry( new KVDutil_GatewayFactory( %s ) );', var_export($data, true));
     return $this->generate($code, $document->documentURI);
 }
 public function execute(AgaviXmlConfigDomDocument $DOM)
 {
     $DOM->setDefaultNamespace(self::$NsValidation["ns"], self::$NsValidation["key"]);
     $xpath = $DOM->getXpath();
     $nsVal = self::$NsValidation["key"];
     $nsValURI = self::$NsValidation["ns"];
     $xpath->registerNamespace(self::$NsEnvelope["key"], self::$NsEnvelope["ns"]);
     $validators = $xpath->query("//" . $nsVal . ":validators");
     $params = array();
     foreach ($validators as $val) {
         if ($val->getAttribute("method") && $val->getAttribute("method") != "write") {
             //only respect POST requests
             continue;
         }
         $validators = $xpath->query("//" . $nsVal . ":validator", $val);
         foreach ($validators as $validator) {
             $params[] = $this->parseRequestParameter($validator);
         }
     }
     return $params;
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @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 <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'routing');
     $routing = AgaviContext::getInstance($this->context)->getRouting();
     // reset the stored route names
     $this->unnamedRoutes = array();
     // clear the routing
     $routing->importRoutes(array());
     foreach ($document->getConfigurationElements() as $cfg) {
         if ($cfg->has('routes')) {
             $this->parseRoutes($routing, $cfg->get('routes'));
         }
     }
     // we cannot do this:
     // $code = '$this->importRoutes(unserialize(' . var_export(serialize($routing->exportRoutes()), true) . '));';
     // return $this->generate($code, $document->documentURI);
     // because var_export() incorrectly escapes null-byte sequences as \000, which results in a corrupted string, and unserialize() doesn't like corrupted strings
     // this was fixed in PHP 5.2.6, but we're compatible with 5.2.0+
     // see http://bugs.php.net/bug.php?id=37262 and http://bugs.php.net/bug.php?id=42272
     return serialize($routing->exportRoutes());
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     Noah Fontes <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'autoload');
     $classes = $namespaces = array();
     foreach ($document->getConfigurationElements() as $configuration) {
         if (!$configuration->has('autoloads')) {
             continue;
         }
         // let's do our fancy work
         foreach ($configuration->get('autoloads') as $autoload) {
             // we can have variables in the filename
             $path = AgaviToolkit::expandDirectives($autoload->getValue());
             // sanity check; XML Schema can't do <xs:choice> on attributes...
             if (($isClass = $autoload->hasAttribute('class')) && $autoload->hasAttribute('namespace')) {
                 $error = sprintf('Configuration file "%s" specifies both "class" and "namespace" attribute for path "%s"', $document->documentURI, $path);
                 throw new AgaviParseException($error);
             }
             // prepend the app dir if the path is not absolute
             $file = self::replacePath($path);
             // check if absolute path is readable or try to resolve it against the include path
             if (!file_exists($file) && ($path == $file || !($file = stream_resolve_include_path($path)))) {
                 // the class path doesn't exist and couldn't be resolved against the include path either
                 $error = sprintf('Configuration file "%s" specifies %s "%s" with non-existent path "%s"', $document->documentURI, $isClass ? 'file' : 'namespace', $isClass ? $autoload->getAttribute('class') : $autoload->getAttribute('namespace'), $path);
                 throw new AgaviParseException($error);
             }
             if ($isClass) {
                 // it's a class
                 $classes[$autoload->getAttribute('class')] = $file;
             } else {
                 // it's a whole namespace
                 // trim backslashes from the namespace and trailing slashes or backslashes from the path
                 $namespaces[trim($autoload->getAttribute('namespace'), '\\')] = rtrim($file, '/\\');
             }
         }
     }
     $code = array('AgaviAutoloader::addClasses(' . var_export($classes, true) . ');', 'AgaviAutoloader::addNamespaces(' . var_export($namespaces, true) . ');');
     return $this->generate($code, $document->documentURI);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     Noah Fontes <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'autoload');
     $data = array();
     foreach ($document->getConfigurationElements() as $configuration) {
         if (!$configuration->has('autoloads')) {
             continue;
         }
         // let's do our fancy work
         foreach ($configuration->get('autoloads') as $autoload) {
             // we can have variables in the filename
             $file = AgaviToolkit::expandDirectives($autoload->getValue());
             // we need the filename w/o app dir prepended since the file could
             // be placed in the include path
             $originalFile = $file;
             // if the filename is not absolute we assume its relative to the app dir
             $file = self::replacePath($file);
             $class = $autoload->getAttribute('name');
             if (!($fp = @fopen($file, 'r', true))) {
                 if ($originalFile != $file && ($fpOriginal = @fopen($originalFile, 'r', true))) {
                     $file = $originalFile;
                     $fp = $fpOriginal;
                 } else {
                     // the class path doesn't exist
                     $error = 'Configuration file "%s" specifies class "%s" with ' . 'nonexistent or unreadable file "%s"';
                     $error = sprintf($error, $document->documentURI, $class, $file);
                     throw new AgaviParseException($error);
                 }
             }
             fclose($fp);
             $data[$class] = $file;
         }
     }
     $code = array('return ' . var_export($data, true) . ';');
     return $this->generate($code, $document->documentURI);
 }
 /**
  * (non-PHPdoc)
  * @see AgaviIXmlConfigHandler::execute()
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $config = basename($document->baseURI, '.xml');
     $refClass = $this->getConfigHandlerClass($config);
     $configHandler = $refClass->newInstance();
     $configHandler->initialize($this->context, $this->parameters);
     $nsprefix = null;
     if ($refClass->hasConstant('XML_NAMESPACE')) {
         $m = array();
         preg_match('/\\/([a-z]+)\\/[^\\/]+$/', $refClass->getConstant('XML_NAMESPACE'), $m);
         $nsprefix = $m[1];
         $document->setDefaultNamespace($refClass->getConstant('XML_NAMESPACE'), $nsprefix);
     } else {
         throw new AgaviConfigurationException('Could not read XML_NAMESPACE from class: ' . $refClass->getName());
     }
     $modules = $this->getAvailableModules();
     $query = $this->getQuery();
     $pointers = $this->getPointers();
     foreach ($modules as $module) {
         $includes = AgaviConfig::get(sprintf(self::INCLUDE_FMT, strtolower($module), $this->getParameter('includeNS', $config)), false);
         if ($includes) {
             if (isset($includes["folder"])) {
                 $includes = $this->resolveFolder($includes);
             }
             foreach ($pointers as $pointer) {
                 AppKitXmlUtil::includeXmlFilesToTarget($document, $query, $pointer, $includes);
                 try {
                     $document->xinclude();
                 } catch (Exception $e) {
                 }
             }
         }
     }
     // The confighandler behind this included definition
     return $configHandler->execute($document);
 }
 /**
  * @see     AgaviRoutingConfigHandler::execute()
  * @author  Marius Hein <*****@*****.**>
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'routing');
     return $this->parent_execute($document);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @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     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'output_types');
     // remember the config file path
     $config = $document->documentURI;
     $data = array();
     $defaultOt = null;
     foreach ($document->getConfigurationElements() as $cfg) {
         if (!$cfg->has('output_types')) {
             continue;
         }
         $otnames = array();
         foreach ($cfg->get('output_types') as $outputType) {
             $otname = $outputType->getAttribute('name');
             if (in_array($otname, $otnames)) {
                 throw new AgaviConfigurationException('Duplicate Output Type "' . $otname . '" in ' . $config);
             }
             $otnames[] = $otname;
         }
         if (!$cfg->getChild('output_types')->hasAttribute('default')) {
             throw new AgaviConfigurationException('No default Output Type specified in ' . $config);
         }
         foreach ($cfg->get('output_types') as $outputType) {
             $outputTypeName = $outputType->getAttribute('name');
             $data[$outputTypeName] = isset($data[$outputTypeName]) ? $data[$outputTypeName] : array('parameters' => array(), 'default_renderer' => null, 'renderers' => array(), 'layouts' => array(), 'default_layout' => null, 'exception_template' => null);
             if ($outputType->has('renderers')) {
                 foreach ($outputType->get('renderers') as $renderer) {
                     $rendererName = $renderer->getAttribute('name');
                     $data[$outputTypeName]['renderers'][$rendererName] = array('class' => $renderer->getAttribute('class'), 'instance' => null, 'parameters' => $renderer->getAgaviParameters(array()));
                 }
                 $data[$outputTypeName]['default_renderer'] = $outputType->getChild('renderers')->getAttribute('default');
             }
             if ($outputType->has('layouts')) {
                 foreach ($outputType->get('layouts') as $layout) {
                     $layers = array();
                     if ($layout->has('layers')) {
                         foreach ($layout->get('layers') as $layer) {
                             $slots = array();
                             if ($layer->has('slots')) {
                                 foreach ($layer->get('slots') as $slot) {
                                     $slots[$slot->getAttribute('name')] = array('action' => $slot->getAttribute('action'), 'module' => $slot->getAttribute('module'), 'output_type' => $slot->getAttribute('output_type'), 'request_method' => $slot->getAttribute('method'), 'parameters' => $slot->getAgaviParameters(array()));
                                 }
                             }
                             $layers[$layer->getAttribute('name')] = array('class' => $layer->getAttribute('class', $this->getParameter('default_layer_class', 'AgaviFileTemplateLayer')), 'parameters' => $layer->getAgaviParameters(array()), 'renderer' => $layer->getAttribute('renderer'), 'slots' => $slots);
                         }
                     }
                     $data[$outputTypeName]['layouts'][$layout->getAttribute('name')] = array('layers' => $layers, 'parameters' => $layout->getAgaviParameters(array()));
                 }
                 $data[$outputTypeName]['default_layout'] = $outputType->getChild('layouts')->getAttribute('default');
             }
             if ($outputType->hasAttribute('exception_template')) {
                 $data[$outputTypeName]['exception_template'] = AgaviToolkit::expandDirectives($outputType->getAttribute('exception_template'));
                 if (!is_readable($data[$outputTypeName]['exception_template'])) {
                     throw new AgaviConfigurationException('Exception template "' . $data[$outputTypeName]['exception_template'] . '" does not exist or is unreadable');
                 }
             }
             $data[$outputTypeName]['parameters'] = $outputType->getAgaviParameters($data[$outputTypeName]['parameters']);
         }
         $defaultOt = $cfg->getChild('output_types')->getAttribute('default');
     }
     if (!isset($data[$defaultOt])) {
         $error = 'Configuration file "%s" specifies undefined default Output Type "%s".';
         $error = sprintf($error, $document->documentURI, $defaultOt);
         throw new AgaviConfigurationException($error);
     }
     $code = array();
     foreach ($data as $outputTypeName => $outputType) {
         $code[] = '$ot = new AgaviOutputType();';
         $code[] = sprintf('$ot->initialize($this->context, %s, %s, %s, %s, %s, %s, %s);', var_export($outputType['parameters'], true), var_export($outputTypeName, true), var_export($outputType['renderers'], true), var_export($outputType['default_renderer'], true), var_export($outputType['layouts'], true), var_export($outputType['default_layout'], true), var_export($outputType['exception_template'], true));
         $code[] = sprintf('$this->outputTypes[%s] = $ot;', var_export($outputTypeName, true));
     }
     $code[] = sprintf('$this->defaultOutputType = %s;', var_export($defaultOt, true));
     return $this->generate($code, $config);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @return     string Data to be written to a cache file.
  *
  * @throws     <b>AgaviParseException</b> If a requested configuration file is
  *                                        improperly formatted.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     Noah Fontes <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'factories');
     $config = $document->documentURI;
     $data = array();
     // The order of this initialization code is fixed, to not change
     // name => required?
     $factories = array('execution_container' => array('required' => true, 'var' => null, 'must_implement' => array()), 'validation_manager' => array('required' => true, 'var' => null, 'must_implement' => array()), 'dispatch_filter' => array('required' => true, 'var' => null, 'must_implement' => array('AgaviIGlobalFilter')), 'execution_filter' => array('required' => true, 'var' => null, 'must_implement' => array('AgaviIActionFilter')), 'security_filter' => array('required' => AgaviConfig::get('core.use_security', false), 'var' => null, 'must_implement' => array('AgaviIActionFilter', 'AgaviISecurityFilter')), 'filter_chain' => array('required' => true, 'var' => null, 'must_implement' => array()), 'response' => array('required' => true, 'var' => null, 'must_implement' => array()), 'database_manager' => array('required' => AgaviConfig::get('core.use_database', false), 'var' => 'databaseManager', 'must_implement' => array()), 'database_manager', 'logger_manager' => array('required' => AgaviConfig::get('core.use_logging', false), 'var' => 'loggerManager', 'must_implement' => array()), 'logger_manager', 'translation_manager' => array('required' => AgaviConfig::get('core.use_translation', false), 'var' => 'translationManager', 'must_implement' => array()), 'request' => array('required' => true, 'var' => 'request', 'must_implement' => array()), 'routing' => array('required' => true, 'var' => 'routing', 'must_implement' => array()), 'controller' => array('required' => true, 'var' => 'controller', 'must_implement' => array()), 'storage' => array('required' => true, 'var' => 'storage', 'must_implement' => array()), 'storage', 'user' => array('required' => true, 'var' => 'user', 'must_implement' => AgaviConfig::get('core.use_security') ? array('AgaviISecurityUser') : array()), 'translation_manager', 'user', 'routing', 'request', 'controller');
     foreach ($document->getConfigurationElements() as $configuration) {
         foreach ($factories as $factory => $info) {
             if (is_array($info) && $info['required'] && $configuration->hasChild($factory)) {
                 $element = $configuration->getChild($factory);
                 $data[$factory] = isset($data[$factory]) ? $data[$factory] : array('class' => null, 'params' => array());
                 $data[$factory]['class'] = $element->getAttribute('class', $data[$factory]['class']);
                 $data[$factory]['params'] = $element->getAgaviParameters($data[$factory]['params']);
             }
         }
     }
     $code = array();
     $shutdownSequence = array();
     foreach ($factories as $factory => $info) {
         if (is_array($info)) {
             if (!$info['required']) {
                 continue;
             }
             if (!isset($data[$factory]) || $data[$factory]['class'] === null) {
                 $error = 'Configuration file "%s" has missing or incomplete entry "%s"';
                 $error = sprintf($error, $config, $factory);
                 throw new AgaviConfigurationException($error);
             }
             try {
                 $rc = new ReflectionClass($data[$factory]['class']);
             } catch (ReflectionException $e) {
                 $error = 'Configuration file "%s" specifies unknown class "%s" for entry "%s"';
                 $error = sprintf($error, $config, $data[$factory]['class'], $factory);
                 throw new AgaviConfigurationException($error);
             }
             foreach ($info['must_implement'] as $interface) {
                 if (!$rc->implementsInterface($interface)) {
                     $error = 'Class "%s" for entry "%s" does not implement interface "%s" in configuration file "%s"';
                     $error = sprintf($error, $data[$factory]['class'], $factory, $interface, $config);
                     throw new AgaviConfigurationException($error);
                 }
             }
             if ($info['var'] !== null) {
                 // we have to make an instance
                 $code[] = sprintf('$this->%1$s = new %2$s();' . "\n" . '$this->%1$s->initialize($this, %3$s);', $info['var'], $data[$factory]['class'], var_export($data[$factory]['params'], true));
             } else {
                 // it's a factory info
                 $code[] = sprintf('$this->factories[%1$s] = %2$s;', var_export($factory, true), var_export(array('class' => $data[$factory]['class'], 'parameters' => $data[$factory]['params']), true));
             }
         } else {
             if ($factories[$info]['required']) {
                 $code[] = sprintf('$this->%s->startup();', $factories[$info]['var']);
                 array_unshift($shutdownSequence, sprintf('$this->%s', $factories[$info]['var']));
             }
         }
     }
     $code[] = sprintf('$this->shutdownSequence = array(%s);', implode(",\n", $shutdownSequence));
     return $this->generate($code, $config);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @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     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'caching');
     $cachings = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         if (!$cfg->has('cachings')) {
             continue;
         }
         foreach ($cfg->get('cachings') as $caching) {
             $groups = array();
             if ($caching->has('groups')) {
                 foreach ($caching->get('groups') as $group) {
                     $groups[] = array('name' => $group->getValue(), 'source' => $group->getAttribute('source', 'string'), 'namespace' => $group->getAttribute('namespace'));
                 }
             }
             $actionAttributes = array();
             if ($caching->has('action_attributes')) {
                 foreach ($caching->get('action_attributes') as $actionAttribute) {
                     $actionAttributes[] = $actionAttribute->getValue();
                 }
             }
             $views = null;
             if ($caching->has('views')) {
                 $views = array();
                 foreach ($caching->get('views') as $view) {
                     if ($view->hasAttribute('module')) {
                         $views[] = array('module' => $view->getAttribute('module'), 'view' => $view->getValue());
                     } else {
                         $views[] = AgaviToolkit::literalize($view->getValue());
                     }
                 }
             }
             $outputTypes = array();
             if ($caching->has('output_types')) {
                 foreach ($caching->get('output_types') as $outputType) {
                     $layers = null;
                     if ($outputType->has('layers')) {
                         $layers = array();
                         foreach ($outputType->get('layers') as $layer) {
                             $include = AgaviToolkit::literalize($layer->getAttribute('include', 'true'));
                             if ($layer->has('slots') && !$layer->hasAttribute('include') || !$include) {
                                 $slots = array();
                                 if ($layer->has('slots')) {
                                     foreach ($layer->get('slots') as $slot) {
                                         $slots[] = $slot->getValue();
                                     }
                                 }
                                 $layers[$layer->getAttribute('name')] = $slots;
                             } else {
                                 $layers[$layer->getAttribute('name')] = true;
                             }
                         }
                     }
                     $templateVariables = array();
                     if ($outputType->has('template_variables')) {
                         foreach ($outputType->get('template_variables') as $templateVariable) {
                             $templateVariables[] = $templateVariable->getValue();
                         }
                     }
                     $requestAttributes = array();
                     if ($outputType->has('request_attributes')) {
                         foreach ($outputType->get('request_attributes') as $requestAttribute) {
                             $requestAttributes[] = array('name' => $requestAttribute->getValue(), 'namespace' => $requestAttribute->getAttribute('namespace'));
                         }
                     }
                     $requestAttributeNamespaces = array();
                     if ($outputType->has('request_attribute_namespaces')) {
                         foreach ($outputType->get('request_attribute_namespaces') as $requestAttributeNamespace) {
                             $requestAttributeNamespaces[] = $requestAttributeNamespace->getValue();
                         }
                     }
                     $otnames = array_map('trim', explode(' ', $outputType->getAttribute('name', '*')));
                     foreach ($otnames as $otname) {
                         $outputTypes[$otname] = array('layers' => $layers, 'template_variables' => $templateVariables, 'request_attributes' => $requestAttributes, 'request_attribute_namespaces' => $requestAttributeNamespaces);
                     }
                 }
             }
             $methods = array_map('trim', explode(' ', $caching->getAttribute('method', '*')));
             foreach ($methods as $method) {
                 if (!AgaviToolkit::literalize($caching->getAttribute('enabled', true))) {
                     unset($cachings[$method]);
                 } else {
                     $values = array('lifetime' => $caching->getAttribute('lifetime'), 'groups' => $groups, 'views' => $views, 'action_attributes' => $actionAttributes, 'output_types' => $outputTypes);
                     $cachings[$method] = $values;
                 }
             }
         }
     }
     $code = array('$configs = ' . var_export($cachings, true) . ';', 'if(isset($configs[$index = $container->getRequestMethod()]) || isset($configs[$index = "*"])) {', '	$isCacheable = true;', '	$config = $configs[$index];', '	if(is_array($config["views"])) {', '		foreach($config["views"] as &$view) {', '			if(!is_array($view)) {', '				if($view === null) {', '					$view = array(', '						"module" => null,', '						"name" => null', '					);', '				} else {', '					$view = array(', '						"module" => $moduleName,', '						"name" => AgaviToolkit::evaluateModuleDirective(', '							$moduleName,', '							"agavi.view.name",', '							array(', '								"actionName" => $actionName,', '								"viewName" => $view,', '							)', '						)', '					);', '				}', '			}', '		}', '	}', '}');
     return $this->generate($code, $document->documentURI);
 }
 /**
  * Execute this configuration handler.
  *
  * @param      AgaviXmlConfigDomDocument The document to parse.
  *
  * @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     David Zülke <*****@*****.**>
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     Bob Zoller <*****@*****.**>
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     // set up our default namespace
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'logging');
     // init our data, includes, methods, appenders and appenders arrays
     $code = array();
     $loggers = array();
     $appenders = array();
     $layouts = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         if ($cfg->has('loggers')) {
             foreach ($cfg->get('loggers') as $logger) {
                 $name = $logger->getAttribute('name');
                 if (!isset($loggers[$name])) {
                     $loggers[$name] = array('class' => null, 'level' => null, 'appenders' => array(), 'params' => array());
                 }
                 $loggers[$name]['class'] = $logger->hasAttribute('class') ? $logger->getAttribute('class') : $loggers[$name]['class'];
                 $loggers[$name]['level'] = $logger->hasAttribute('level') ? $logger->getAttribute('level') : $loggers[$name]['level'];
                 if ($logger->has('appenders')) {
                     foreach ($logger->get('appenders') as $appender) {
                         $loggers[$name]['appenders'][] = $appender->getValue();
                     }
                 }
                 $loggers[$name]['params'] = $logger->getAgaviParameters($loggers[$name]['params']);
             }
         }
         if ($cfg->has('appenders')) {
             foreach ($cfg->get('appenders') as $appender) {
                 $name = $appender->getAttribute('name');
                 if (!isset($appenders[$name])) {
                     $appenders[$name] = array('class' => null, 'layout' => null, 'params' => array());
                 }
                 $appenders[$name]['class'] = $appender->hasAttribute('class') ? $appender->getAttribute('class') : $appenders[$name]['class'];
                 $appenders[$name]['layout'] = $appender->hasAttribute('layout') ? $appender->getAttribute('layout') : $appenders[$name]['layout'];
                 $appenders[$name]['params'] = $appender->getAgaviParameters($appenders[$name]['params']);
             }
         }
         if ($cfg->has('layouts')) {
             foreach ($cfg->get('layouts') as $layout) {
                 $name = $layout->getAttribute('name');
                 if (!isset($layouts[$name])) {
                     $layouts[$name] = array('class' => null, 'params' => array());
                 }
                 $layouts[$name]['class'] = $layout->hasAttribute('class') ? $layout->getAttribute('class') : $layouts[$name]['class'];
                 $layouts[$name]['params'] = $layout->getAgaviParameters($layouts[$name]['params']);
             }
         }
         if ($cfg->has('loggers')) {
             $defaultLogger = $cfg->getChild('loggers')->getAttribute('default');
             if (!isset($loggers[$defaultLogger])) {
                 throw new AgaviConfigurationException(sprintf('Logger "%s" is configured as default, but does not exist.', $defaultLogger));
             }
         }
     }
     if (count($loggers) > 0) {
         foreach ($layouts as $name => $layout) {
             if (!isset($layout['class'])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml has no class defined for layout "%s".', $name));
             } elseif (!class_exists($layout['class'])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml specifies unknown class "%s" for layout "%s".', $layout['class'], $name));
             }
             $code[] = sprintf('${%s} = new %s();', var_export('_layout_' . $name, true), $layout['class']);
             $code[] = sprintf('${%s}->initialize($this->context, %s);', var_export('_layout_' . $name, true), var_export($layout['params'], true));
         }
         foreach ($appenders as $name => $appender) {
             if (!isset($appender['class'])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml has no class defined for appender "%s".', $name));
             } elseif (!class_exists($appender['class'])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml specifies unknown class "%s" for appender "%s".', $appender['class'], $name));
             }
             $code[] = sprintf('${%s} = new %s();', var_export('_appender_' . $name, true), $appender['class']);
             $code[] = sprintf('${%s}->initialize($this->context, %s);', var_export('_appender_' . $name, true), var_export($appender['params'], true));
             if (!isset($appender['layout'])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml has no layout defined for appender "%s".', $name));
             } elseif (!isset($layouts[$appender['layout']])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml specifies unknown layout "%s" for appender "%s".', $appender['layout'], $name));
             }
             $code[] = sprintf('${%s}->setLayout(${%s});', var_export('_appender_' . $name, true), var_export('_layout_' . $appender['layout'], true));
         }
         foreach ($loggers as $name => $logger) {
             if (!isset($logger['class'])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml has no class defined for logger "%s".', $name));
             } elseif (!class_exists($logger['class'])) {
                 throw new AgaviConfigurationException(sprintf('logging.xml specifies unknown class "%s" for logger "%s".', $logger['class'], $name));
             }
             $code[] = sprintf('${%s} = new %s();', var_export('_logger_' . $name, true), $logger['class']);
             foreach ($logger['appenders'] as $appender) {
                 if (!isset($appenders[$appender])) {
                     throw new AgaviConfigurationException(sprintf('logging.xml specifies unknown appender "%s" for logger "%s".', $appender, $name));
                 }
                 $code[] = sprintf('${%s}->setAppender(%s, ${%s});', var_export('_logger_' . $name, true), var_export($appender, true), var_export('_appender_' . $appender, true));
             }
             if ($logger['level'] !== null) {
                 $code[] = sprintf('${%s}->setLevel(%s);', var_export('_logger_' . $name, true), $logger['level']);
             }
             $code[] = sprintf('$this->setLogger(%s, ${%s});', var_export($name, true), var_export('_logger_' . $name, true));
         }
         $code[] = sprintf('$this->setDefaultLoggerName(%s);', var_export($defaultLogger, true));
     }
     return $this->generate($code, $document->documentURI);
 }