Source for file Tree.class.php
Documentation is available at Tree.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* Abstract Tree Class for Composite Interface
* The abstract Tree class provides general implementation to common methods
* of Composite classes. Typically, Composite classes should extend an
* abstract class (such as this one). This assists in eliminating having to
* implement all the methods of the Composite Interface.
* The full Composite structure will consist of a Branch and a Leaf (both
* extending the abstract Tree). Some Composite definitions will consist
* of Components and other language. The use of Tree-Branch-Leaf keeps the
* idea of a tree structure more direct (especially those new to Design Patterns).
* Tree-Branch-Leaf is the same as Component-Composite-Leaf, just smaller names.
* The Branch will hold the other Tree objects. Every Composite will start
* with a Branch object (trunk). Additional Tree elements can be added to
* The Leaf is a single name=>value element. It is the lowest form of data
* that can be held by a Composite. A Leaf cannot hold other Tree elements.
* To create a Composite structure, start with the first Branch (trunk), and
* add the necessary elements as required. If a Branch is added with the same
* name as another Branch, a numerical reference will be applied. Think of
* an XML file with multiple tags of the same name. To access a numerical
* reference, simply place the number inside curly braces.
* // access second Leaf element value
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @desc Abstract Tree Class for Composite Interface
gumbo_load ("Interface_Composite");
abstract class Gumbo_Tree implements Gumbo_Interface_Composite {
/** @var int|string$_name Composite name */
/** @var mixed $_value Composite value */
/** @var array $_attr list of Attributes */
/** @var array $_comments list of Comments */
* Adds an attribute description to the Composite object
* @postcondition remove non-alphanumeric characters (excluding underscores) from $name
* @param string $name attribute name
* @param string|num|bool$val attribute value
* @param bool $replace replaces duplicate attribute
* @throws Gumbo_Exception
public function addAttribute ($name, $val, $replace=
false) {
$e->setFunction (__METHOD__
);
$this->_attr [$name] =
$val;
if (!isset
($this->_attr [$name])) {
$this->_attr [$name] =
$val;
$e->setFunction (__METHOD__
);
* @throws Gumbo_Exception
if (!isset
($this->_attr [$name])) {
unset
($this->_attr [$name]);
$e->setFunction (__METHOD__
);
* Adds a comment to the Composite (A null comment will add a blank line)
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* @postcondition !getComments()
* @postcondition removes all non-alphanumeric characters (excluding underscores)
* @throws Gumbo_Exception
protected function setName ($name=
null) {
$e->setFunction (__METHOD__
);
* Sets the Composite value (for Leaf use only)
* @param mixed $val (primitive types only)
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* @return mixed (primitive type)
* Returns an attribute value
* @return mixed (primitive values only)
* @throws Gumbo_Exception
if (!isset
($this->_attr [$name])) {
return $this->_attr [$name];
$e->setFunction (__METHOD__
);
* Returns all attributes of the Composite