Changeset 3002

Show
Ignore:
Timestamp:
10/08/08 19:58:55 (3 months ago)
Author:
david
Message:

Added getAttributes() and getAttributesNS() and cleaned up a bit (comments), refs #519

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/src/config/util/dom/AgaviXmlConfigDomElement.class.php

    r3001 r3002  
    33class AgaviXmlConfigDomElement extends DOMElement implements IteratorAggregate 
    44{ 
     5  /** 
     6   * __toString() magic method, returns the element value. 
     7   * 
     8   * @see        AgaviXmlConfigDomElement::getValue() 
     9   * 
     10   * @return     string The element value. 
     11   * 
     12   * @author     David Zülke <david.zuelke@bitextender.com> 
     13   * @since      1.0.0 
     14   */ 
    515  public function __toString() 
    616  { 
     
    818  } 
    919   
     20  /** 
     21   * Returns the element name. 
     22   * 
     23   * @return     string The element name. 
     24   * 
     25   * @author     David Zülke <david.zuelke@bitextender.com> 
     26   * @since      1.0.0 
     27   */ 
    1028  public function getName() 
    1129  { 
     
    1533  } 
    1634   
     35  /** 
     36   * Returns the element value. 
     37   * 
     38   * @return     string The element value. 
     39   * 
     40   * @author     David Zülke <david.zuelke@bitextender.com> 
     41   * @since      1.0.0 
     42   */ 
    1743  public function getValue() 
    1844  { 
     
    2854   * @return     Iterator An iterator. 
    2955   * 
    30    * @author     David Zülke <dz@bitxtender.com> 
     56   * @author     David Zülke <david.zuelke@bitextender.com> 
    3157   * @since      1.0.0 
    3258   */ 
     
    4268  } 
    4369   
     70  /** 
     71   * Retrieve singular form of given element name. 
     72   * This does special splitting only of the last part of the name if the name 
     73   * of the element contains hyphens, underscores or dots. 
     74   * 
     75   * @param      string The element name to singularize. 
     76   * 
     77   * @return     string The singularized element name. 
     78   * 
     79   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     80   * @since      1.0.0 
     81   */ 
    4482  protected function singularize($name) 
    4583  { 
     84    // TODO: shouldn't this be static? 
    4685    $names = preg_split('#([_\-\.])#', $name, -1, PREG_SPLIT_DELIM_CAPTURE); 
    4786    $names[count($names) - 1] = AgaviInflector::singularize(end($names)); 
     
    268307   * @see        DOMElement::getAttribute() 
    269308   * 
    270    * @author     David Zülke <dz@bitxtender.com> 
     309   * @author     David Zülke <david.zuelke@bitextender.com> 
    271310   * @since      1.0.0 
    272311   */ 
     
    298337   * @see        DOMElement::getAttributeNS() 
    299338   * 
    300    * @author     David Zülke <dz@bitxtender.com> 
     339   * @author     David Zülke <david.zuelke@bitextender.com> 
    301340   * @since      1.0.0 
    302341   */ 
     
    307346    if($retval === null) { 
    308347      $retval = $default; 
     348    } 
     349     
     350    return $retval; 
     351  } 
     352   
     353  /** 
     354   * Retrieve all attributes of the element that are in no namespace. 
     355   * 
     356   * @return     array An associative array of attribute names and values. 
     357   * 
     358   * @author     David Zülke <david.zuelke@bitextender.com> 
     359   * @since      1.0.0 
     360   */ 
     361  public function getAttributes() 
     362  { 
     363    return $this->getAttributesNS(''); 
     364  } 
     365   
     366  /** 
     367   * Retrieve all attributes of the element that are in the given namespace. 
     368   * 
     369   * @return     array An associative array of attribute names and values. 
     370   * 
     371   * @author     David Zülke <david.zuelke@bitextender.com> 
     372   * @since      1.0.0 
     373   */ 
     374  public function getAttributesNS($namespaceUri) 
     375  { 
     376    $retval = array(); 
     377     
     378    foreach($this->ownerDocument->getXpath()->query(sprintf('@*[namespace-uri() = "%s"]', $namespaceUri), $this) as $attribute) { 
     379      $retval[$attribute->localName] = $attribute->nodeValue; 
    309380    } 
    310381