Source for file Leaf.class.php

Documentation is available at Leaf.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 Leaf Class
  22.  * 
  23.  * This class holds a single value (primitive type).  It is only responsible
  24.  * for this data.  It is the smallest element of the Tree, which means that
  25.  * no additional Branches can be added.
  26.  * 
  27.  * To retrieve the value of a Leaf, simply use the 'get' method, or by using
  28.  * the overload method with any string (except 'name'):
  29.  * <pre>
  30.  * // the following will return the value
  31.  * $leaf->getValue ();
  32.  * $leaf->get ();
  33.  * $leaf->value;
  34.  * $leaf->some_other_string_not_name;
  35.  * 
  36.  * // to get the name
  37.  * $leaf->getName ();
  38.  * $leaf->get ("name");
  39.  * $leaf->name;
  40.  * </pre>
  41.  *
  42.  * @category Gumbo
  43.  * @package Composite
  44.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  45.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  46.  * @author Michael Luster <mluster79@yahoo.com>
  47.  * @link http://sourceforge.net/projects/phpgumbo
  48.  * @desc Composite Pattern Leaf Class
  49.  * @version 0.0.1
  50.  */
  51.  
  52. gumbo_load ("Tree");
  53.  
  54. class Gumbo_Leaf extends Gumbo_Tree {
  55.     
  56.     /**
  57.      * Constructor, Creates new Leaf
  58.      * @param mix $val value of Leaf
  59.      * @param int|string$name name of Leaf
  60.      */
  61.     public function __construct ($val$name=null{
  62.         $this->setValue ($val);
  63.         $this->setName ($name);
  64.     }
  65.     
  66.     /**
  67.      * Sets the value (use any key string)
  68.      * @param string $name 
  69.      * @param mixed $val 
  70.      */
  71.     public function __set ($name$val{
  72.         $this->setValue ($val);
  73.     }
  74.     
  75.     /**
  76.      * Returns the value of the given element
  77.      * 
  78.      * The parameter can either be the actual name of the Leaf object, or
  79.      * the actual property needed to be accessed ("name", "value").  Problems
  80.      * can occur if the $name of the Leaf actually is "name".  Use getName () or
  81.      * getValue () for more specific access to values.
  82.      * 
  83.      * @param int|string$name use 'name' to get the name or any string to retrieve the value
  84.      * @return mixed 
  85.      */
  86.     public function __get ($name{
  87.         return $this->get ($name);
  88.     }
  89.     
  90.     
  91.     
  92.     /** ACCESSOR METHODS **/
  93.     /**
  94.      * Returns the corresponding Composite object or value (use 'name' for the Composite Name)
  95.      * @param int|string$name 
  96.      * @return mix 
  97.      */
  98.     public function get ($name=null{
  99.         switch ($name{
  100.             case "name" return $this->getName ()break;
  101.             default return $this->getValue ();
  102.         }
  103.     }
  104.     
  105.     
  106.     
  107.     /** ABSTRACT METHODS **/
  108.     /**
  109.      * Adds a Composite object to the Composite (for Branch use only) (method does nothing)
  110.      * @param Gumbo_Interface_Composite $tree 
  111.      * @param bool $replace replaces the original Composite object
  112.      */
  113.     public function add (Gumbo_Interface_Composite $tree$replace=false{
  114.         return;
  115.     }
  116.     
  117.     /**
  118.      * Removes a Composite object based on the Composite name (for Branch use only) (method does nothing)
  119.      * @param int|string$name 
  120.      */
  121.     public function remove ($name{
  122.         return;
  123.     }
  124.     
  125. }
  126.  
  127. ?>