Changeset 2640

Show
Ignore:
Timestamp:
08/01/08 11:00:37 (5 months ago)
Author:
impl
Message:

branches/david-xml_only_config_system (refs #519): fix AgaviXmlConfigDomElement::getAgaviParameters() and add documentation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/david-xml_only_config_system/src/config/util/dom/AgaviXmlConfigDomElement.class.php

    r2632 r2640  
    7171  } 
    7272   
     73  /** 
     74   * Count the number of child elements with a given name. 
     75   * 
     76   * @param      string The name of the element. 
     77   * @param      string The namespace URI. If null, the document default 
     78   *                    namespace will be used. If an empty string, no namespace 
     79   *                    will be used. 
     80   * 
     81   * @return     int The number of child elements with the given name. 
     82   * 
     83   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     84   * @since      1.0.0 
     85   */ 
    7386  public function countChildren($name, $namespaceUri = null) 
    7487  { 
     
    8699  } 
    87100   
     101  /** 
     102   * Determine whether there is at least one instance of a child element with a 
     103   * given name. 
     104   * 
     105   * @param      string The name of the element. 
     106   * @param      string The namespace URI. If null, the document default 
     107   *                    namespace will be used. If an empty string, no namespace 
     108   *                    will be used. 
     109   * 
     110   * @return     bool True if one or more child elements with the given name 
     111   *                  exist, false otherwise. 
     112   * 
     113   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     114   * @since      1.0.0 
     115   */ 
    88116  public function hasChildren($name, $namespaceUri = null) 
    89117  { 
     
    91119  } 
    92120   
     121  /** 
     122   * Retrieve all children with the given element name. 
     123   * 
     124   * @param      string The name of the element. 
     125   * @param      string The namespace URI. If null, the document default 
     126   *                    namespace will be used. If an empty string, no namespace 
     127   *                    will be used. 
     128   * 
     129   * @return     DOMNodeList A list of the child elements. 
     130   * 
     131   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     132   * @since      1.0.0 
     133   */ 
    93134  public function getChildren($name, $namespaceUri = null) 
    94135  { 
     
    107148  } 
    108149   
     150  /** 
     151   * Determine whether this element has a particular child element. This method 
     152   * succeeds only when there is exactly one child element with the given name. 
     153   * 
     154   * @param      string The name of the element. 
     155   * @param      string The namespace URI. If null, the document default 
     156   *                    namespace will be used. If an empty string, no namespace 
     157   *                    will be used. 
     158   * 
     159   * @return     bool True if there is exactly one instance of an element with 
     160   *                  the given name; false otherwise. 
     161   * 
     162   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     163   * @since      1.0.0 
     164   */ 
    109165  public function hasChild($name, $namespaceUri = null) 
    110166  { 
     
    117173   
    118174  /** 
    119    * Returns a single child element with a given name. 
     175   * Return a single child element with a given name. 
    120176   * 
    121177   * @param      string The name of the element. 
     
    194250  } 
    195251   
    196   public function getAgaviParameters(array $existing = array()) 
    197   { 
     252  /** 
     253   * Retrieve all of the Agavi parameter elements associated with this 
     254   * element. 
     255   * 
     256   * @param      array An array of existing parameters. 
     257   * @param      bool  Whether or not input values should be literalized once 
     258   *                   they are read. 
     259   * 
     260   * @return     array The complete array of parameters. 
     261   * 
     262   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     263   * @since      1.0.0 
     264   */ 
     265  public function getAgaviParameters(array $existing = array(), $literalize = true) 
     266  { 
     267    $result = $existing; 
     268     
    198269    if($this->ownerDocument->isAgaviConfiguration()) { 
    199270      $elements = $this->getChildren('parameters', AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_LATEST); 
    200       $result = array(); 
    201271       
    202272      foreach($elements as $element) { 
     273        $key = null; 
     274        if(!$element->hasAttribute('name')) { 
     275          $result[] = null; 
     276          end($result); 
     277          $key = key($result); 
     278        } else { 
     279          $key = $element->getAttribute('name'); 
     280        } 
     281         
    203282        if($element->hasChildren('parameters', AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_LATEST)) { 
    204           $result[$element->getAttribute('name')] = $element->getAgaviParameters(); 
     283          $result[$key] = isset($result[$key]) && is_array($result[$key]) ? $result[$key] : array(); 
     284          $result[$key] = $element->getAgaviParameters($result[$key], $literalize); 
    205285        } else { 
    206           $result[$element->getAttribute('name')] = $element->getValue(); 
     286          $result[$key] = $literalize ? AgaviToolkit::literalize($element->getValue()) : $element->getValue(); 
    207287        } 
    208288      } 
    209        
    210       return array_merge($existing, $result); 
    211     } else { 
    212       return $existing; 
    213     } 
     289    } 
     290     
     291    return $result; 
    214292  } 
    215293}