Location: PHPKode > scripts > UI Template > ui-template/frea/Template/Dom/Node/Element.php
<?php
/**
 * template dom node element class
 *
 * @package frea-framework
 * @subpackage Template
 * 
 * @copyright 2009 frea-framework
 * @author Dawid Kraczkowski hide@address.com
 * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 */
class Template_Dom_Node_Element extends Template_Dom_Node 
{
	/**
	 * child nodes of element
	 *
	 * @var array
	 */
	protected $childNodes;
	/**
	 * attributes of element
	 *
	 * @var array
	 */
	protected $attributes;
	
	public $parser;
	/**
	 * constructor
	 *
	 * @param string $nodeName
	 */
	public function __construct($nodeName)
	{
		
		$this->nodeType = Template_Dom_Node::UIELEMENT_NODE ;
		$this->nodeName = $nodeName;
	}
	/**
	 * append a new child
	 *
	 * @param Template_Dom_Node $node
	 * @return Template_Dom_Node
	 */
	public function appendChild(Template_Dom_Node &$node)
	{
		$node->setParent($this);
		$this->childNodes[] = $node;
		return $node;
	}
	/**
	 * remove a child node
	 *
	 * @param Template_Dom_Node $node
	 */
	public function removeChild(Template_Dom_Node $node)
	{
		foreach($this->childNodes as &$child)
		{
			if($child === $node)
				unset($child);
		}
	}
	/**
	 * sets owner document
	 *
	 * @param Template_Dom_Node_Document $document
	 */
	protected function setOwnerDocument(Template_Dom_Node_Document &$document)
	{
		$this->ownerDocument = $document;
	}
	/**
	 * return true if element has childNodes
	 *
	 * @return bool
	 */
	public function hasChildNodes()
	{
		return (bool) count($this->childNodes);
	}
	/**
	 * returns children nodes
	 *
	 * @return array
	 */
	public function children()
	{
		return $this->childNodes;
	}
	/**
	 * returns children with given name
	 *
	 * @param string $name
	 * @return array
	 */
	public function getElementsByTagname($name)
	{
		if($this->childNodes)
		{
			$elements = array();
			foreach ($this->childNodes as &$child)
			{
				if($child->nodeName() == $name)
					$elements[] = $child;
			}
			return $elements;
		}
		return null;
	}
	/**
	 * check for attributes
	 *
	 * @return boolean
	 */
	public function hasAttributes()
	{
		if(count($this->attributes))
			return true;
		return false;
	}
	/**
	 * check if given attribute exists
	 *
	 * @param string $attrName
	 * @return boolean
	 */
	public function hasAttribute($attrName)
	{
		if(isset($this->attributes[$attrName]))
			return true;
		return false;
	}
	/**
	 * Sets an attribute for current tag
	 *
	 * @param string $name
	 * @param string $value
	 */
	public function setAttribute($name,$value=null)
	{
		$this->attributes[$name] = &new Template_Dom_Node_Attribute($name,$value);
	}
	public function getAttribute($name)
	{
		return (string)$this->attributes[$name];
	}
	public function getAttributes()
	{
		return $this->attributes;
	}
	
}
Return current item: UI Template