Changeset 2581

Show
Ignore:
Timestamp:
07/07/08 04:38:07 (6 months ago)
Author:
david
Message:

Now setting "matched" attribute flags on appropriate <configuration> elements. And some cleanup. Refs #519, #710

Location:
branches/david-xml_only_config_system/src/config
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/david-xml_only_config_system/src/config/AgaviXmlConfigParser.class.php

    r2572 r2581  
    4747   */ 
    4848  public static $agaviEnvelopeNamespaces = array( 
    49     self::AGAVI_ENVELOPE_NAMESPACE_1_0 => 'ae10', 
     49    self::AGAVI_ENVELOPE_NAMESPACE_1_0 => 'agavi_envelope_1_0', 
    5050  ); 
    5151   
     
    7474   */ 
    7575  protected $xpath = null; 
     76   
     77  /** 
     78   * Test if the given document looks like an Agavi config file. 
     79   * 
     80   * @param      DOMDocument The document to test. 
     81   * 
     82   * @return     bool True, if it is an Agavi config document, false otherwise. 
     83   * 
     84   * @author     David Zülke <david.zuelke@bitextender.com> 
     85   * @since      1.0.0 
     86   */ 
     87  public static function isAgaviConfigurationDocument(DOMDocument $doc) 
     88  { 
     89    return $doc->documentElement && $doc->documentElement->localName == 'configurations' && self::isAgaviEnvelopeNamespace($doc->documentElement->namespaceURI); 
     90  } 
    7691   
    7792  /** 
     
    117132      // make sure it (still) is a <configurations> file with the proper agavi namespace 
    118133      if($isAgaviConfigFormat) { 
    119         $isAgaviConfigFormat = $doc->documentElement && $doc->documentElement->localName == 'configurations' && self::isAgaviEnvelopeNamespace($doc->documentElement->namespaceURI); 
     134        $isAgaviConfigFormat = self::isAgaviConfigurationDocument($doc); 
    120135      } 
    121136       
     
    161176     
    162177      $configurationOrder = array( 
    163         'count(self::node()[not(@environment) and not(@context)])', 
    164         'count(self::node()[@environment and not(@context)])', 
    165         'count(self::node()[not(@environment) and @context])', 
    166         'count(self::node()[@environment and @context])', 
     178        'count(self::node()[@agavi_envelope_1_0:matched and not(@environment) and not(@context)])', 
     179        'count(self::node()[@agavi_envelope_1_0:matched and @environment and not(@context)])', 
     180        'count(self::node()[@agavi_envelope_1_0:matched and not(@environment) and @context])', 
     181        'count(self::node()[@agavi_envelope_1_0:matched and @environment and @context])', 
    167182      ); 
    168183      $testAttributes = array( 
     
    175190        foreach($configurationElements as &$element) { 
    176191          if($element->ownerDocument->xpath->evaluate($xpath, $element)) { 
    177             foreach($testAttributes as $attributeName => $attributeValue) { 
    178               // TODO: move that method or something 
    179               if($element->hasAttribute($attributeName) && !self::testPattern($element->getAttribute($attributeName), $attributeValue)) { 
    180                 continue 2; 
    181               } 
    182             } 
    183192            $importedNode = $retval->importNode($element, true); 
    184193            $retval->documentElement->appendChild($importedNode); 
     
    241250    libxml_clear_errors(); 
    242251     
    243     $this->doc = new DOMDocument(); 
     252    $this->doc = new AgaviXmlConfigDomDocument(); 
    244253    $this->doc->load($path); 
    245254     
     
    302311   
    303312  /** 
    304    * Prepare the configuration file, resolve XIncludes, and validate embedded 
    305    * XML Schemas. 
     313   * Prepare the configuration file: resolve XIncludes, validate against XML 
     314   * Schema instances declared on the document, and set processing information 
     315   * flags on <configuration> elements. 
    306316   * 
    307317   * @author     David Zülke <dz@bitxtender.com> 
     
    393403      } 
    394404      $this->validateXmlschemaSource($schemas); 
     405    } 
     406     
     407    if($this->doc->isAgaviConfiguration()) { 
     408      $testAttributes = array( 
     409        'context' => $this->context, 
     410        'environment' => $this->environment, 
     411      ); 
     412       
     413      foreach($this->doc->getConfigurationElements() as $configuration) { 
     414        $matched = true; 
     415        foreach($testAttributes as $attributeName => $attributeValue) { 
     416          if($configuration->hasAttribute($attributeName)) { 
     417            $matched = $matched && self::testPattern($configuration->getAttribute($attributeName), $attributeValue); 
     418          } 
     419        } 
     420        if($matched) { 
     421          $configuration->setAttributeNS(self::AGAVI_ENVELOPE_NAMESPACE_LATEST, 'matched', 'true'); 
     422        } 
     423      } 
    395424    } 
    396425  } 
  • branches/david-xml_only_config_system/src/config/dom/AgaviXmlConfigDomDocument.class.php

    r2482 r2581  
    135135  public function isAgaviConfiguration() 
    136136  { 
    137     return AgaviXmlConfigParser::isAgaviEnvelopeNamespace($this->documentElement->namespaceURI); 
     137    return AgaviXmlConfigParser::isAgaviConfigurationDocument($this); 
    138138  } 
    139139   
     
    166166    $retval = array(); 
    167167     
    168     if($this->isAgaviConfigurationFile()) { 
     168    if($this->isAgaviConfiguration()) { 
    169169      $agaviNs = $this->getAgaviEnvelopeNamespace(); 
    170170