Changeset 1923

Show
Ignore:
Timestamp:
05/11/07 10:30:50 (20 months ago)
Author:
david
Message:

more work on native XML config handlers, refs #519

Location:
branches/david-xml_config_handlers/src/config
Files:
1 added
8 modified

Legend:

Unmodified
Added
Removed
  • branches/david-xml_config_handlers/src/config/AgaviBaseConfigHandler.class.php

    r1917 r1923  
    103103 
    104104  /** 
    105    * Execute this configuration handler. 
    106    * 
    107    * @param      string An absolute filesystem path to a configuration file. 
    108    * @param      string Name of the executing context (if any). 
    109    * 
    110    * @return     string Data to be written to a cache file. 
    111    * 
    112    * @throws     <b>AgaviUnreadableException</b> If a requested configuration 
    113    *                                             file does not exist or is not 
    114    *                                             readable. 
    115    * @throws     <b>AgaviParseException</b> If a requested configuration file is 
    116    *                                        improperly formatted. 
    117    * 
    118    * @author     Sean Kerr <skerr@mojavi.org> 
    119    * @since      0.9.0 
    120    */ 
    121   abstract function execute($config, $context = null); 
    122  
    123   /** 
    124105   * Generate the code for returning from execute(). 
    125106   * 
     
    145126  } 
    146127   
    147   /** 
    148    * Initialize this ConfigHandler. 
    149    * 
    150    * @param      string The path to a validation file for this config handler. 
    151    * @param      string The parser class to use. 
    152    * @param      array An associative array of initialization parameters. 
    153    * 
    154    * @throws     <b>AgaviInitializationException</b> If an error occurs while 
    155    *                                                 initializing the 
    156    *                                                 ConfigHandler 
    157    * 
    158    * @author     Dominik del Bondio <ddb@bitxtender.com> 
    159    * @since      0.9.0 
    160    */ 
    161   public function initialize($validationFile = null, $parser = null, $parameters = array()) 
    162   { 
    163     $this->validationFile = $validationFile; 
    164     $this->parser = $parser; 
    165     $this->setParameters($parameters); 
    166   } 
    167  
    168128  /** 
    169129   * Literalize a string value. 
  • branches/david-xml_config_handlers/src/config/AgaviConfigCache.class.php

    r1920 r1923  
    9999    $handler = new $handlerInfo['class']; 
    100100    if($handler instanceof AgaviIXmlConfigHandler) { 
     101      // a new-style config handler 
     102      // it does not parse the config itself; instead, it is given an array of parsed DOM documents (with parents!) 
     103      $parser = new AgaviXmlConfigParser(); 
     104      $docs = $parser->parseAll($config, $handlerInfo['validation']); 
    101105       
     106      if($context !== null) { 
     107        $context = AgaviContext::getInstance($context); 
     108      } 
     109       
     110      $handler->initialize($context, $handlerInfo['parameters']); 
     111       
     112      try { 
     113        $data = $handler->execute($docs); 
     114      } catch(AgaviException $e) { 
     115        throw new $e(sprintf("Compliation of configuration file '%s' failed for the following reason(s):\n\n%s", $config, $e->getMessage())); 
     116      } 
    102117    } else { 
    103       if(isset($handlerInfo['validation'])) 
    104       $handler->initialize($handlerInfo['validation'], null, $handlerInfo['parameters']); 
    105     } 
    106      
    107     $data = $handler->execute($config, $context); 
     118      $validationFile = null; 
     119      if(isset($handlerInfo['validation'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0])) { 
     120        $validationFile = $handlerInfo['validation'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0]; 
     121      } 
     122      $handler->initialize($validationFile, null, $handlerInfo['parameters']); 
     123      $data = $handler->execute($config, $context); 
     124    } 
     125     
    108126    self::writeCacheFile($config, $cache, $data, false); 
    109127  } 
     
    240258    // since we only need the parser and handlers when the config is not cached 
    241259    // it is sufficient to include them at this stage 
     260    require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviILegacyConfigHandler.interface.php'); 
     261    require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviIXmlConfigHandler.class.php'); 
    242262    require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviBaseConfigHandler.class.php'); 
    243263    require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigHandler.class.php'); 
    244     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviIXmlConfigHandler.class.php'); 
    245264    require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviXmlConfigHandler.class.php'); 
    246265    require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviAutoloadConfigHandler.class.php'); 
     
    328347   * @since      0.11.0 
    329348   */ 
    330   public static function parseConfig($config, $autoloadParser = true, $validateFile = null, $parserClass = null) 
     349  public static function parseConfig($config, $autoloadParser = true, $validationFile = null, $parserClass = null) 
    331350  { 
    332351    $parser = new AgaviConfigParser(); 
    333352     
    334     return $parser->parse($config, $validateFile); 
     353    return $parser->parse($config, $validationFile); 
    335354  } 
    336355} 
  • branches/david-xml_config_handlers/src/config/AgaviConfigHandler.class.php

    r1917 r1923  
    3333 * @version    $Id$ 
    3434 */ 
    35 abstract class AgaviConfigHandler extends AgaviBaseConfigHandler 
     35abstract class AgaviConfigHandler extends AgaviBaseConfigHandler implements AgaviILegacyConfigHandler 
    3636{ 
     37  /** 
     38   * Initialize this ConfigHandler. 
     39   * 
     40   * @param      string The path to a validation file for this config handler. 
     41   * @param      string The parser class to use. 
     42   * @param      array An associative array of initialization parameters. 
     43   * 
     44   * @throws     <b>AgaviInitializationException</b> If an error occurs while 
     45   *                                                 initializing the 
     46   *                                                 ConfigHandler 
     47   * 
     48   * @author     Dominik del Bondio <ddb@bitxtender.com> 
     49   * @since      0.9.0 
     50   */ 
     51  public function initialize($validationFile = null, $parser = null, $parameters = array()) 
     52  { 
     53    $this->validationFile = $validationFile; 
     54    $this->parser = $parser; 
     55    $this->setParameters($parameters); 
     56  } 
    3757} 
    3858 
  • branches/david-xml_config_handlers/src/config/AgaviConfigParser.class.php

    r1920 r1923  
    4848   * @since      0.11.0 
    4949   */ 
    50   public function parse($config, array $validationInfo = array()) 
     50  public function parse($config, $validationFile = null) 
    5151  { 
    5252    $parser = new AgaviXmlConfigParser(); 
    5353     
    54     $doc = $parser->parse($config, $validationInfo); 
     54    $validation = array(); 
     55    if($validationFile !== null) { 
     56      $validation[AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA] = array($validationFile); 
     57    } 
     58    $doc = $parser->parse($config, $validation); 
    5559     
    5660    $this->encoding = $doc->encoding; 
  • branches/david-xml_config_handlers/src/config/AgaviIXmlConfigHandler.class.php

    r1917 r1923  
    3131interface AgaviIXmlConfigHandler 
    3232{ 
     33  /** 
     34   * Initialize this ConfigHandler. 
     35   * 
     36   * @param      AgaviContext The context to work with (if available). 
     37   * @param      array        An associative array of initialization parameters. 
     38   * 
     39   * @throws     <b>AgaviInitializationException</b> If an error occurs while 
     40   *                                                 initializing the 
     41   *                                                 ConfigHandler 
     42   * 
     43   * @author     David Zülke <dz@bitxtender.com> 
     44   * @since      0.11.0 
     45   */ 
     46  public function initialize(AgaviContext $context = null, $parameters = array()); 
     47   
     48  /** 
     49   * Execute this configuration handler. 
     50   * 
     51   * @param      array An array of DOMDocuments (the config and all parents). 
     52   * 
     53   * @return     string Data to be written to a cache file. 
     54   * 
     55   * @throws     <b>AgaviParseException</b> If a requested configuration file is 
     56   *                                        improperly formatted. 
     57   * 
     58   * @author     David Zülke <dz@bitxtender.com> 
     59   * @since      0.11.0 
     60   */ 
     61  public function execute(array $array = array()); 
    3362} 
     63 
     64?> 
  • branches/david-xml_config_handlers/src/config/AgaviXmlConfigHandler.class.php

    r1920 r1923  
    2828 * @version    $Id$ 
    2929 */ 
    30 class AgaviXmlConfigHandler extends AgaviBaseConfigHandler implements AgaviIXmlConfigHandler 
     30abstract class AgaviXmlConfigHandler extends AgaviBaseConfigHandler implements AgaviIXmlConfigHandler 
    3131{ 
    32   public function execute($config, $context = null) 
     32  /** 
     33   * @var        AgaviContext The context to work with (if available). 
     34   */ 
     35  protected $context = null; 
     36   
     37  /** 
     38   * Initialize this ConfigHandler. 
     39   * 
     40   * @param      AgaviContext The context to work with (if available). 
     41   * @param      array        An associative array of initialization parameters. 
     42   * 
     43   * @throws     <b>AgaviInitializationException</b> If an error occurs while 
     44   *                                                 initializing the 
     45   *                                                 ConfigHandler 
     46   * 
     47   * @author     David Zülke <dz@bitxtender.com> 
     48   * @since      0.11.0 
     49   */ 
     50  public function initialize(AgaviContext $context = null, $parameters = array()) 
    3351  { 
     52    $this->context = $context; 
     53    $this->setParameters($parameters); 
    3454  } 
    3555} 
     56 
     57?> 
  • branches/david-xml_config_handlers/src/config/AgaviXmlConfigParser.class.php

    r1920 r1923  
    2929 * @version    $Id$ 
    3030 */ 
    31 class AgaviXmlConfigParser extends AgaviConfigParser 
     31class AgaviXmlConfigParser 
    3232{ 
    3333  const XML_NAMESPACE = 'http://agavi.org/agavi/1.0/config'; 
     
    4444   * 
    4545   * @return     array An array of DOMDocuments (from child to parent). 
     46   * 
     47   * @author     David Zülke <dz@bitxtender.com> 
     48   * @author     Dominik del Bondio <ddb@bitxtender.com> 
     49   * @since      0.11.0 
     50   */ 
     51  public function parseAll($config, array $validation = array()) 
     52  { 
     53    $retval = array(); 
     54     
     55    $nextConfig = $config; 
     56     
     57    while($nextConfig !== null) { 
     58      $doc = $this->parse($nextConfig, $validation); 
     59       
     60      if($doc->documentElement->hasAttribute('parent')) { 
     61        $nextConfig = AgaviBaseConfigHandler::literalize($doc->documentElement->getAttribute('parent')); 
     62      } else { 
     63        $nextConfig = null; 
     64      } 
     65       
     66      $retval[] = $doc; 
     67    } 
     68     
     69    return $retval; 
     70  } 
     71   
     72  /** 
     73   * @param      string An absolute filesystem path to a configuration file. 
     74   * @param      array  An associative array of validation information. 
     75   * 
     76   * @return     DOMDocument A DOMDocument. 
    4677   * 
    4778   * @author     David Zülke <dz@bitxtender.com> 
  • branches/david-xml_config_handlers/src/config/defaults/config_handlers.xml

    r1910 r1923  
    3636      <handler pattern="%core.config_dir%/routing.xml" validate="%core.agavi_dir%/config/xsd/routing.xsd" class="AgaviRoutingConfigHandler" /> 
    3737 
     38      <handler pattern="%core.config_dir%/wsdl.xml" validate="%core.agavi_dir%/config/xsd/routing.xsd" class="AgaviWsdlConfigHandler" /> 
     39 
    3840      <handler pattern="%core.config_dir%/translation.xml" validate="%core.agavi_dir%/config/xsd/translation.xsd" class="AgaviTranslationConfigHandler" /> 
    3941