Ejemplo n.º 1
0
 public function testNormalizePath()
 {
     $this->assertEquals('path', AgaviToolkit::normalizePath("path"));
     $this->assertEquals('/path/warm/hot/unbearable', AgaviToolkit::normalizePath('/path/warm/hot/unbearable'));
     $this->assertEquals('/path/warm/hot/unbearable', AgaviToolkit::normalizePath('\\path\\warm\\hot\\unbearable'));
     $this->assertEquals('/path/warm/hot//unbearable', AgaviToolkit::normalizePath('\\path\\warm\\hot\\\\unbearable'));
 }
Ejemplo n.º 2
0
 public function testCheckConfig()
 {
     $config = AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . 'autoload.xml';
     $config = AgaviToolkit::normalizePath($config);
     $expected = AgaviConfigCache::getCacheName($config);
     if (file_exists($expected)) {
         unlink($expected);
     }
     $cacheName = AgaviConfigCache::checkConfig($config);
     $this->assertEquals($expected, $cacheName);
     $this->assertFileExists($cacheName);
 }
 public function testConfigHandlersConfigHandler()
 {
     $hf = AgaviToolkit::normalizePath(AgaviConfig::get('core.config_dir') . '/routing.xml');
     $CHCH = new AgaviConfigHandlersConfigHandler();
     $document = $this->parseConfiguration(AgaviConfig::get('core.config_dir') . '/tests/config_handlers.xml', AgaviConfig::get('core.agavi_dir') . '/config/xsl/config_handlers.xsl');
     $file = $this->getIncludeFile($CHCH->execute($document));
     $handlers = (include $file);
     unlink($file);
     $this->assertCount(1, $handlers);
     $this->assertTrue(isset($handlers[$hf]));
     $this->assertSame('CHCHTestHandler', $handlers[$hf]['class']);
     $this->assertSame(AgaviConfig::get('core.agavi_dir') . '/config/xsd/routing.xsd', $handlers[$hf]['validations']['single']['transformations_after']['xml_schema'][0]);
     $this->assertSame(array('foo' => 'bar', 'dir' => AgaviConfig::get('core.agavi_dir')), $handlers[$hf]['parameters']);
 }
 /**
  * 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);
 }
 /**
  * Fetches the Validation xml for the action/module combination and returns it as
  * an DOMDocument
  *
  * @param    string  The module name
  * @param    string  The action to get the validation xml for
  * @return   AgaviXmlConfigDomDocument
  *
  * @author   Jannis Moßhammer<*****@*****.**>
  * @throws   AgaviConfigurationException     when module or action does not exist
  */
 protected function getValidatorXMLForAction($module, $action)
 {
     // get Module path
     $path = AgaviToolkit::literalize('%core.module_dir%') . "/" . $module;
     if (!file_exists(AgaviToolkit::normalizePath($path))) {
         throw new AgaviConfigurationException("Couldn't find module " . $module);
     }
     // get Validation file
     $actionPath = str_replace(".", "/", $action);
     $xml = $path . "/validate/" . $actionPath . ".xml";
     if (!file_exists(AgaviToolkit::normalizePath($path))) {
         throw new AgaviConfigurationException("Couldn't find validation file for " . $action);
     }
     $dom = new AgaviXmlConfigDomDocument();
     $dom->load(AgaviToolKit::normalizePath($xml));
     //TODO: Validate xml
     return $dom;
 }
 /**
  * Check to see if a configuration file has been modified and if so
  * recompile the cache file associated with it.
  *
  * If the configuration file path is relative, the path itself is relative
  * to the Agavi "core.app_dir" application setting.
  *
  * @param      string A filesystem path to a configuration file.
  * @param      string An optional context name for which the config should be
  *                    read.
  *
  * @return     string An absolute filesystem path to the cache filename
  *                    associated with this specified configuration file.
  *
  * @throws     <b>AgaviUnreadableException</b> If a requested configuration
  *                                             file does not exist.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public static function checkConfig($config, $context = null)
 {
     $config = AgaviToolkit::normalizePath($config);
     // the full filename path to the config, which might not be what we were given.
     $filename = AgaviToolkit::isPathAbsolute($config) ? $config : AgaviToolkit::normalizePath(AgaviConfig::get('core.app_dir')) . '/' . $config;
     if (!is_readable($filename)) {
         throw new AgaviUnreadableException('Configuration file "' . $filename . '" does not exist or is unreadable.');
     }
     // the cache filename we'll be using
     $cache = self::getCacheName($config, $context);
     if (self::isModified($filename, $cache)) {
         // configuration file has changed so we need to reparse it
         self::callHandler($config, $filename, $cache, $context);
     }
     return $cache;
 }