Gumbo_Tree
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.
Branch The Branch will hold the other Tree objects. Every Composite will start with a Branch object (trunk). Additional Tree elements can be added to populate the Tree.
Leaf 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 $branch->{1}->value;
Author(s): |
Michael Luster <mluster79@yahoo.com> |
License: | New BSD License |
Copyright: | Copyright (c) 2007, iBayou, Michael Luster |
Link: | http://sourceforge.net/projects/phpgumbo |
Version: | 0.0.1 |
Implements interfaces:
Child classes:
Class Variables
Class Methods
Adds an attribute description to the Composite object
Parameter(s):
- (string) $name :: attribute name
- (string|num|bool) $val :: attribute value
- (bool) $replace :: replaces duplicate attribute
- postcondition:
remove non-alphanumeric characters (excluding underscores) from $name - throws:
Gumbo_Exception Implementation of:
[ Top ]public void addComment ( [string $comment] ) [line 151]Adds a comment to the Composite (A null comment will add a blank line)
Parameter(s):
- (string) $comment
- throws:
Gumbo_Exception Implementation of:
[ Top ]public mixed getAttribute ( string $name ) [line 241]Returns an attribute value
Parameter(s):
- (string) $name
- return:
(primitive values only) - throws:
Gumbo_Exception Implementation of:
[ Top ]public array getAttributes ( ) [line 263]Returns all attributes of the Composite
Implementation of:
[ Top ](primitive type) Implementation of:
[ Top ]public void removeAttribute ( string $name ) [line 129]Removes an attribute
Parameter(s):
- (string) $name
- throws:
Gumbo_Exception Implementation of:
[ Top ]!getComments() Implementation of:
[ Top ]protected void setName ( [int|string $name] ) [line 182]Sets the Tree name
Parameter(s):
- (int|string) $name
- postcondition:
removes all non-alphanumeric characters (excluding underscores) - throws:
Gumbo_Exception
[ Top ]public void setValue ( mixed $val ) [line 202]Sets the Composite value (for Leaf use only)
Parameter(s):
- (mixed) $val :: (primitive types only)
- throws:
Gumbo_Exception Implementation of:
[ Top ]