Source for file Composite.class.php

Documentation is available at Composite.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Composite
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Composite Pattern Interface
  22.  * 
  23.  * The Composite Pattern is responsible for holding multi-tiered data into an
  24.  * easily accessible interface.  This would be similar to accessing the elements
  25.  * of a multi-dimensional array.  A Composite can hold other Composite objects.
  26.  * 
  27.  * Attributes
  28.  * An Attribute is simply a key=>val pair of data used to provide more details
  29.  * about a particular Composite.  The best example is an attribute inside an
  30.  * XML element.
  31.  * <pre>
  32.  * <xml id="value">data</xml>
  33.  * </pre>
  34.  * 
  35.  * Comments
  36.  * This feature is useless, unless the Composite is being used to read/write
  37.  * files with comments.  This feature will allow the object to hold comments
  38.  * for a particular Composite, which can be used by a file writer to include
  39.  * in particular parts of the file.
  40.  * 
  41.  * Look at the Tree-Branch-Leaf classes for more details on implementing a
  42.  * Composite.
  43.  *
  44.  * @category Gumbo
  45.  * @package Composite
  46.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  47.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  48.  * @author Michael Luster <mluster79@yahoo.com>
  49.  * @link http://sourceforge.net/projects/phpgumbo
  50.  * @desc Composite Pattern Interface
  51.  * @version 0.0.1
  52.  * @see Gumbo_Tree
  53.  */
  54.  
  55.     
  56.     /** OVERLOAD METHODS **/
  57.     /**
  58.      * Sets a Value, or adds a new Composite to a Branch
  59.      * @param int|string$name (for 'int', wrap in curly braces $comp->{0} = value)
  60.      * @param mixed $val 
  61.      */
  62.     public function __set ($name$val);
  63.     
  64.     /**
  65.      * Returns the Value or a Composite referenced by the 'name'
  66.      * @param int|string$name (for 'int', wrap in curly braces $comp->{0})
  67.      * @return mixed 
  68.      */
  69.     public function __get ($name);
  70.     
  71.     
  72.     
  73.     /** ABSTRACT METHODS **/
  74.     /**
  75.      * Adds a Composite object to the Composite (for Branch use only)
  76.      * @param Gumbo_Interface_Composite $tree 
  77.      * @param bool $replace replaces the original Composite object
  78.      */
  79.     public function add (Gumbo_Interface_Composite $tree$replace=false);
  80.     
  81.     /**
  82.      * Removes a Composite object based on the Composite name (for Branch use only)
  83.      * @param int|string$name 
  84.      */
  85.     public function remove ($name);
  86.     
  87.     
  88.     
  89.     /** ACTION METHODS **/
  90.     /**
  91.      * Adds an attribute description to the Composite object
  92.      * @postcondition remove non-alphanumeric characters (excluding underscores) from $name
  93.      * @param string $name attribute name
  94.      * @param string|num|bool$val attribute value
  95.      * @param bool $replace replaces existing attribute
  96.      */
  97.     public function addAttribute ($name$val$replace=false);
  98.  
  99.     /**
  100.      * Removes an attribute
  101.      * @param string $name 
  102.      */
  103.     public function removeAttribute ($name);
  104.  
  105.     /**
  106.      * Adds a comment to the Composite (A null comment will add a blank line)
  107.      * @param string $comment 
  108.      */
  109.     public function addComment ($comment=null);
  110.  
  111.     /**
  112.      * Resets all comments
  113.      * @postcondition !getComments()
  114.      */
  115.     public function resetComments ();
  116.     
  117.     
  118.     
  119.     /** MUTATOR METHODS **/
  120.     /**
  121.      * Sets the Composite value (for Leaf use only)
  122.      * @param mixed $val (primitive types only)
  123.      */
  124.     public function setValue ($val);
  125.     
  126.     
  127.     
  128.     /** ACCESSOR METHODS **/
  129.     /**
  130.      * Returns the corresponding Composite object or Value
  131.      * @param int|string$name 
  132.      * @return mixed 
  133.      */
  134.     public function get ($name=null);
  135.     
  136.     /**
  137.      * Returns the Name
  138.      * @return int|string
  139.      */
  140.     public function getName ();
  141.     
  142.     /**
  143.      * Returns the Value
  144.      * @return mixed 
  145.      */
  146.     public function getValue ();
  147.     
  148.     /**
  149.      * Returns an attribute value
  150.      * @param string $name 
  151.      * @return mixed (primitive values only)
  152.      */
  153.     public function getAttribute ($name);
  154.     
  155.     /**
  156.      * Returns all attributes of the Composite
  157.      * @return array 
  158.      */
  159.     public function getAttributes ();
  160.     
  161.     /**
  162.      * Returns all comments
  163.      * @return array 
  164.      */
  165.     public function getComments ();
  166.     
  167. }
  168.  
  169. ?>