Changeset 2648

Show
Ignore:
Timestamp:
08/09/08 17:09:55 (5 months ago)
Author:
david
Message:

merging in branches/david-xml_only_config_system, kudos to impl for helping so much with this one :> please test it thoroughly; more work on migration of other config handlers will be done over the next couple of weeks. refs #519, #462, #710, #515

Location:
trunk
Files:
23 modified
32 copied

Legend:

Unmodified
Added
Removed
  • trunk/COPYRIGHT

    r2228 r2648  
    6161 
    6262 
     63ISO Schematron 
     64-------------- 
     65 
     66This software uses the ISO Schematron Skeleton, and the ISO Schematron ISO SVRL 
     67implementation, by Rick Jelliffe. 
     68 
     69For more information about ISO Schematron, visit the homepage: 
     70http://www.schematron.com/ 
     71 
     72Copyright (c) 2000-2007 Rick Jelliffe and Academia Sinica Computing Center, TW 
     73 
     74-- 
     75 
     76 
    6377Zoneinfo Database 
    6478----------------- 
  • trunk/LICENSE

    r2619 r2648  
    7474 
    7575 
     76ISO Schematron 
     77-------------- 
     78 
     79This software uses the ISO Schematron Skeleton, and the ISO Schematron ISO SVRL 
     80implementation, by Rick Jelliffe. 
     81 
     82For more information about ISO Schematron, visit the homepage: 
     83http://www.schematron.com/ 
     84 
     85The corresponding license can be found in LICENSE-SCHEMATRON. 
     86 
     87-- 
     88 
     89 
    7690Zoneinfo Database 
    7791----------------- 
  • trunk/samples/app/config/config_handlers.xml

    r1964 r2648  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <configurations xmlns="http://agavi.org/agavi/1.0/config" parent="%core.system_config_dir%/config_handlers.xml"> 
     2<configurations xmlns="http://agavi.org/agavi/1.0/config" parent="%core.system_config_dir%/config_handlers.xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanceZOMGNO" xsi:schemaLocation="http://agavi.org/agavi/1.0/config http://localhost/~dzuelke/Code/oss/agavi/branches/david-xml_only_config_system/src/config/xsd/autoload.xsd"> 
    33</configurations> 
  • trunk/samples/app/config/factories.xml

    r2396 r2648  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <configurations xmlns="http://agavi.org/agavi/1.0/config"> 
     2<a:configurations xmlns:a="http://agavi.org/agavi/1.0/config" xmlns="http://agavi.org/agavi/1.0/config"> 
    33   
    4   <configuration> 
     4  <foo:bar xmlns:foo="urn:bar" /> 
     5   
     6  <a:configuration> 
    57     
    68    <controller class="AgaviController" /> 
     
    3335     
    3436    <validation_manager class="AgaviValidationManager"> 
    35       <parameter name="mode">strict</parameter> 
     37      <a:parameter name="mode">strict</a:parameter> 
    3638    </validation_manager> 
    3739     
    38   </configuration> 
     40  </a:configuration> 
    3941   
    40   <configuration environment="development.*"> 
     42  <a:configuration environment="development.*"> 
    4143     
    4244    <validation_manager class="AgaviValidationManager"> 
    43       <parameter name="mode">conditional</parameter> 
     45      <a:parameter name="mode">conditional</a:parameter> 
    4446    </validation_manager> 
    4547     
    46   </configuration> 
     48  </a:configuration> 
    4749   
    48   <configuration context="web" environment="development.*"> 
     50  <a:configuration context="web" environment="development.*"> 
    4951     
    5052    <response class="AgaviWebResponse"> 
    51       <parameter name="send_content_length">false</parameter> 
     53      <a:parameter name="send_content_length">false</a:parameter> 
    5254    </response> 
    5355   
    54   </configuration> 
     56  </a:configuration> 
    5557   
    56   <configuration context="soap"> 
     58  <a:configuration context="soap"> 
    5759     
    5860    <controller class="AgaviSoapController" /> 
     
    6365     
    6466    <routing class="AgaviSoapRouting"> 
    65       <parameter name="wsdl_generator"> 
    66         <parameter name="soap"> 
    67           <parameter name="address"> 
    68             <parameter name="location">http://localhost/~dzuelke/_projects/agavi/branches/0.11/samples/pub/soap.php</parameter> 
    69           </parameter> 
    70         </parameter> 
    71       </parameter> 
     67      <a:parameter name="wsdl_generator"> 
     68        <a:parameter name="soap"> 
     69          <a:parameter name="address"> 
     70            <a:parameter name="location">http://localhost/~dzuelke/_projects/agavi/branches/0.11/samples/pub/soap.php</a:parameter> 
     71          </a:parameter> 
     72        </a:parameter> 
     73      </a:parameter> 
    7274    </routing> 
    7375     
    7476    <user class="AgaviSecurityUser" /> 
    7577     
    76   </configuration> 
     78  </a:configuration> 
    7779   
    78   <configuration context="wsdl"> 
     80  <a:configuration context="wsdl"> 
    7981     
    8082    <storage class="AgaviSessionStorage"> 
    81       <parameter name="auto_start">false</parameter> 
     83      <a:parameter name="auto_start">false</a:parameter> 
    8284    </storage> 
    8385     
    8486    <user class="AgaviSecurityUser" /> 
    8587     
    86   </configuration> 
     88  </a:configuration> 
    8789   
    88   <configuration context="xmlrpc"> 
     90  <a:configuration context="xmlrpc"> 
    8991     
    9092    <request class="AgaviXmlrpcepiphpRequest" /> 
     
    9698    <user class="AgaviSecurityUser" /> 
    9799     
    98   </configuration> 
     100  </a:configuration> 
    99101   
    100 </configurations> 
     102</a:configurations> 
  • trunk/samples/app/config/routing.xml

    r2646 r2648  
    5353  </configuration> 
    5454   
     55  <configuration context="soap2"> 
     56    <routes> 
     57      <!-- SOAP calls include the name of a remote method to call. The WebserviceRouting applies patterns to this method name, not to the URL of the request. We set the request method to "read" here so executeRead() is run in the Action. --> 
     58      <route pattern="^getItemPrice2$" module="Default" action="SearchEngineSpam" method="read"> 
     59        <wsdl:input> 
     60          <wsdl:part name="name" type="xsd:string" /> 
     61        </wsdl:input> 
     62        <wsdl:output> 
     63          <wsdl:part name="price" type="xsd:float" /> 
     64        </wsdl:output> 
     65      </route> 
     66    </routes> 
     67  </configuration> 
     68   
    5569  <configuration context="wsdl"> 
    5670    <routes> 
  • trunk/src/config/AgaviBaseConfigHandler.class.php

    r2481 r2648  
    3535abstract class AgaviBaseConfigHandler extends AgaviParameterHolder 
    3636{ 
    37   /** 
    38    * @var        string An absolute filesystem path to a validation filename. 
    39    */ 
    40   protected $validationFile = null; 
    41  
    42   /** 
    43    * @var        string A class name of the class which should be used to parse 
    44    *                    Input files of this config handler. 
    45    */ 
    46   protected $parser = null; 
    47  
    48   /** 
    49    * Retrieves the stored validation filename. 
    50    * 
    51    * @return     string An absolute filesystem path to a validation filename. 
    52    * 
    53    * @author     Dominik del Bondio <ddb@bitxtender.com> 
    54    * @since      0.11.0 
    55    */ 
    56   public function getValidationFile() 
    57   { 
    58     return $this->validationFile; 
    59   } 
    60  
    61   /** 
    62    * Retrieve the parameter node values of the given item's parameters element. 
    63    * 
    64    * @param      ConfigValueHolder The node that contains a parameters chiild. 
    65    * @param      array             As associative array of parameters that will 
    66    *                               be overwritten if appropriate. 
    67    * @param      boolean           Whether or not values should be literalized. 
    68    * 
    69    * @return     array An associative array of parameters 
    70    * 
    71    * @author     Dominik del Bondio <ddb@bitxtender.com> 
    72    * @since      0.11.0 
    73    */ 
    74   protected function getItemParameters($itemNode, $oldValues = array(), $literalize = true) 
    75   { 
    76     $data = array(); 
    77     if($itemNode->hasChildren('parameters')) { 
    78       foreach($itemNode->parameters as $node) { 
    79         if(!$node->hasAttribute('name')) { 
    80           // create a new entry in in the array and get they key of the new 
    81           // created entry (the last in the array). The value doesn't matter 
    82           // since it will be overwritten anyways 
    83           $data[] = 0; 
    84           end($data); 
    85           $name = key($data); 
    86         } else { 
    87           $name = $node->getAttribute('name'); 
    88         } 
    89         if($node->hasChildren('parameters')) { 
    90           $data[$name] = (isset($oldValues[$name]) && is_array($oldValues[$name])) ? $oldValues[$name] : array(); 
    91           $data[$name] = $this->getItemParameters($node, $data[$name], $literalize); 
    92         } else { 
    93           $data[$name] = $literalize ? AgaviToolkit::literalize($node->getValue()) : $node->getValue(); 
    94         } 
    95       } 
    96     } 
    97     // we can NOT use array_merge here, since it would break numeric keys 
    98     foreach($data as $key => $value) { 
    99       $oldValues[$key] = $value; 
    100     } 
    101     return $oldValues; 
    102   } 
    103  
    10437  /** 
    10538   * Generate the code for returning from execute(). 
     
    183116    return $path; 
    184117  } 
    185    
    186   /** 
    187    * Builds a proper regular expression from the input pattern to test against 
    188    * the given subject. This is for "environment" and "context" attributes of 
    189    * configuration blocks in the files. 
    190    * 
    191    * @param      string A regular expression chunk without delimiters/anchors. 
    192    * 
    193    * @return     bool Whether or not the subject matched the pattern. 
    194    * 
    195    * @author     David Zülke <dz@bitxtender.com> 
    196    * @since      0.11.0 
    197    */ 
    198   public static function testPattern($pattern, $subject) 
    199   { 
    200     return (preg_match('/^(' . implode('|', array_map('trim', explode(' ', $pattern))) . ')$/', $subject) > 0); 
    201   } 
    202  
    203   /** 
    204    * Returns a properly ordered array of AgaviConfigValueHolder configuration 
    205    * elements for given env and context. 
    206    * 
    207    * @param      AgaviConfigValueHolder The root config element 
    208    * @param      string                 An environment name. 
    209    * @param      string                 A context name. 
    210    * @param      bool                   Whether the parser class should be 
    211    *                                    autoloaded or not. 
    212    * 
    213    * @return     array An array of ConfigValueHolder configuration elements. 
    214    * 
    215    * @author     David Zülke <dz@bitxtender.com> 
    216    * @since      0.11.0 
    217    */ 
    218   public function orderConfigurations(AgaviConfigValueHolder $configurations, $environment = null, $context = null, $autoloadParser = true) 
    219   { 
    220     $configs = array(); 
    221  
    222     if($configurations->hasAttribute('parent')) { 
    223       $parent = AgaviToolkit::literalize($configurations->getAttribute('parent')); 
    224       $parentConfigs = $this->orderConfigurations(AgaviConfigCache::parseConfig($parent, $autoloadParser, $this->getValidationFile(), $this->parser)->configurations, $environment, $context, $autoloadParser); 
    225       $configs = array_merge($configs, $parentConfigs); 
    226     } 
    227  
    228     foreach($configurations as $cfg) { 
    229       if(!$cfg->hasAttribute('environment') && !$cfg->hasAttribute('context')) { 
    230         $configs[] = $cfg; 
    231       } 
    232     } 
    233     foreach($configurations as $cfg) { 
    234       if($environment !== null && $cfg->hasAttribute('environment') && self::testPattern($cfg->getAttribute('environment'), $environment) && !$cfg->hasAttribute('context')) { 
    235         $configs[] = $cfg; 
    236       } 
    237     } 
    238     foreach($configurations as $cfg) { 
    239       if(!$cfg->hasAttribute('environment') && $context !== null && $cfg->hasAttribute('context') && self::testPattern($cfg->getAttribute('context'), $context)) { 
    240         $configs[] = $cfg; 
    241       } 
    242     } 
    243     foreach($configurations as $cfg) { 
    244       if($environment !== null && $cfg->hasAttribute('environment') && self::testPattern($cfg->getAttribute('environment'), $environment) && $context !== null && $cfg->hasAttribute('context') && self::testPattern($cfg->getAttribute('context'), $context)) { 
    245         $configs[] = $cfg; 
    246       } 
    247     } 
    248  
    249     return $configs; 
    250   } 
    251118} 
    252119 
  • trunk/src/config/AgaviConfigCache.class.php

    r2509 r2648  
    100100    if($handler instanceof AgaviIXmlConfigHandler) { 
    101101      // 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']); 
     102      // it does not parse the config itself; instead, it is given a complete and merged DOM document 
     103      $doc = AgaviXmlConfigParser::run($config, AgaviConfig::get('core.environment'), $context, $handlerInfo['transformations'], $handlerInfo['validations']); 
    105104 
    106105      if($context !== null) { 
     
    111110 
    112111      try { 
    113         $data = $handler->execute($docs); 
     112        $data = $handler->execute($doc); 
    114113      } 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())); 
     114        throw new $e(sprintf("Compilation of configuration file '%s' failed for the following reason(s):\n\n%s", $config, $e->getMessage())); 
    116115      } 
    117116    } else { 
    118117      $validationFile = null; 
    119       if(isset($handlerInfo['validation'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0])) { 
    120         $validationFile = $handlerInfo['validation'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0]; 
     118      if(isset($handlerInfo['validations'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0])) { 
     119        $validationFile = $handlerInfo['validations'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0]; 
    121120      } 
    122121      $handler->initialize($validationFile, null, $handlerInfo['parameters']); 
     
    272271  private static function loadConfigHandlers() 
    273272  { 
     273    $agaviDir = AgaviConfig::get('core.agavi_dir'); 
    274274    // since we only need the parser and handlers when the config is not cached 
    275275    // it is sufficient to include them at this stage 
    276     require_once(AgaviConfig::get('core.agavi_dir') . '/config/AgaviILegacyConfigHandler.interface.php'); 
    277     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviIXmlConfigHandler.interface.php'); 
    278     require_once(AgaviConfig::get('core.agavi_dir') . '/config/AgaviBaseConfigHandler.class.php'); 
    279     require_once(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigHandler.class.php'); 
    280     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviXmlConfigHandler.class.php'); 
    281     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviAutoloadConfigHandler.class.php'); 
    282     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigHandlersConfigHandler.class.php'); 
    283     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigValueHolder.class.php'); 
    284     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigParser.class.php'); 
    285     require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviXmlConfigParser.class.php'); 
    286  
     276    require_once($agaviDir . '/config/AgaviILegacyConfigHandler.interface.php'); 
     277    require($agaviDir . '/config/AgaviIXmlConfigHandler.interface.php'); 
     278    require_once($agaviDir . '/config/AgaviBaseConfigHandler.class.php'); 
     279    require_once($agaviDir . '/config/AgaviConfigHandler.class.php'); 
     280    require($agaviDir . '/config/AgaviXmlConfigHandler.class.php'); 
     281    require($agaviDir . '/config/AgaviAutoloadConfigHandler.class.php'); 
     282    require($agaviDir . '/config/AgaviConfigHandlersConfigHandler.class.php'); 
     283    require($agaviDir . '/config/AgaviConfigValueHolder.class.php'); 
     284    require($agaviDir . '/config/AgaviConfigParser.class.php'); 
     285    require($agaviDir . '/config/AgaviXmlConfigParser.class.php'); 
     286    // extended DOM* classes 
     287    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomAttr.class.php'); 
     288    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomCharacterData.class.php'); 
     289    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomComment.class.php'); 
     290    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomDocument.class.php'); 
     291    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomDocumentFragment.class.php'); 
     292    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomDocumentType.class.php'); 
     293    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomElement.class.php'); 
     294    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomEntity.class.php'); 
     295    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomEntityReference.class.php'); 
     296    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomNode.class.php'); 
     297    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomNotation.class.php'); 
     298    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomProcessingInstruction.class.php'); 
     299    require($agaviDir . '/config/util/dom/AgaviXmlConfigDomText.class.php'); 
     300    // extended XSL* classes 
     301    if(!AgaviConfig::get('core.skip_config_transformations', false)) { 
     302      if(!extension_loaded('xsl')) { 
     303        throw new AgaviConfigurationException('The XSL extension is required for performing transformations in the configuration system; transformations may be disabled by setting the core.skip_config_transformations directive'); 
     304      } 
     305      require($agaviDir . '/config/util/xsl/AgaviXmlConfigXsltProcessor.class.php'); 
     306    } 
     307     
    287308    // manually create our config_handlers.xml handler 
    288309    self::$handlers['config_handlers.xml'] = array( 
     
    290311      'parameters' => array( 
    291312      ), 
    292       'validation' => array( 
    293         AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array( 
    294           AgaviConfig::get('core.agavi_dir') . '/config/xsd/config_handlers.xsd', 
     313      'transformations' => array( 
     314        AgaviXmlConfigParser::STAGE_SINGLE => array( 
     315          $agaviDir . '/config/xsl/config_handlers.xsl', 
     316        ), 
     317        AgaviXmlConfigParser::STAGE_COMPILATION => array( 
     318        ), 
     319      ), 
     320      'validations' => array( 
     321        AgaviXmlConfigParser::STAGE_SINGLE => array( 
     322          AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array( 
     323          ), 
     324          AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array( 
     325            AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array( 
     326              $agaviDir . '/config/rng/config_handlers.rng', 
     327            ), 
     328          ), 
     329        ), 
     330        AgaviXmlConfigParser::STAGE_COMPILATION => array( 
     331          AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array(), 
     332          AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array() 
    295333        ), 
    296334      ), 
  • trunk/src/config/AgaviConfigHandler.class.php

    r2509 r2648  
    3838{ 
    3939  /** 
     40   * @var        string An absolute filesystem path to a validation filename. 
     41   */ 
     42  protected $validationFile = null; 
     43 
     44  /** 
     45   * @var        string A class name of the class which should be used to parse 
     46   *                    Input files of this config handler. 
     47   */ 
     48  protected $parser = null; 
     49   
     50  /** 
     51   * Retrieve the parameter node values of the given item's parameters element. 
     52   * 
     53   * @param      ConfigValueHolder The node that contains a parameters chiild. 
     54   * @param      array             As associative array of parameters that will 
     55   *                               be overwritten if appropriate. 
     56   * @param      boolean           Whether or not values should be literalized. 
     57   * 
     58   * @return     array An associative array of parameters 
     59   * 
     60   * @author     Dominik del Bondio <ddb@bitxtender.com> 
     61   * @since      0.11.0 
     62   */ 
     63  protected function getItemParameters($itemNode, $oldValues = array(), $literalize = true) 
     64  { 
     65    $data = array(); 
     66    if($itemNode->hasChildren('parameters')) { 
     67      foreach($itemNode->parameters as $node) { 
     68        if(!$node->hasAttribute('name')) { 
     69          // create a new entry in in the array and get they key of the new 
     70          // created entry (the last in the array). The value doesn't matter 
     71          // since it will be overwritten anyways 
     72          $data[] = 0; 
     73          end($data); 
     74          $name = key($data); 
     75        } else { 
     76          $name = $node->getAttribute('name'); 
     77        } 
     78        if($node->hasChildren('parameters')) { 
     79          $data[$name] = (isset($oldValues[$name]) && is_array($oldValues[$name])) ? $oldValues[$name] : array(); 
     80          $data[$name] = $this->getItemParameters($node, $data[$name], $literalize); 
     81        } else { 
     82          $data[$name] = $literalize ? AgaviToolkit::literalize($node->getValue()) : $node->getValue(); 
     83        } 
     84      } 
     85    } 
     86    // we can NOT use array_merge here, since it would break numeric keys 
     87    foreach($data as $key => $value) { 
     88      $oldValues[$key] = $value; 
     89    } 
     90    return $oldValues; 
     91  } 
     92 
     93  /** 
    4094   * Initialize this ConfigHandler. 
    4195   * 
     
    57111    $this->setParameters($parameters); 
    58112  } 
     113   
     114  /** 
     115   * Retrieves the stored validation filename.