Coverage for Doctrine_Tree

Back to coverage report

1 <?php
2 /*
3  *  $Id: Tree.php 3975 2008-03-13 02:16:21Z jwage $
4  *
5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16  *
17  * This software consists of voluntary contributions made by many individuals
18  * and is licensed under the LGPL. For more information, see
19  * <http://www.phpdoctrine.org>.
20  */
21                  
22 /**
23  * Doctrine_Tree
24  *
25  * @package     Doctrine
26  * @subpackage  Tree
27  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28  * @link        www.phpdoctrine.org
29  * @since       1.0
30  * @version     $Revision: 3975 $
31  * @author      Joe Simms <joe.simms@websites4.com>
32  */
33 class Doctrine_Tree
34 {
35     /**
36      * @param object $table   reference to associated Doctrine_Table instance
37      */
38     protected $table;
39
40     /**
41      * @param array $options
42      */
43     protected $options = array();
44     
45     protected $_baseComponent;
46
47     /**
48      * constructor, creates tree with reference to table and any options
49      *
50      * @param object $table                     instance of Doctrine_Table
51      * @param array $options                    options
52      */
53     public function __construct(Doctrine_Table $table, $options)
54     {
55         $this->table = $table;
56         $this->options = $options;
57         $this->_baseComponent = $table->getComponentName();
58         $class = $this->_baseComponent;
59         if ($table->getOption('inheritanceMap')) {
60             $subclasses = $table->getOption('subclasses');
61             while (in_array($class, $subclasses)) {
62                 $class = get_parent_class($class);
63             }
64             $this->_baseComponent = $class;
65         }
66         //echo $this->_baseComponent;
67     }
68
69     /**
70      * Used to define table attributes required for the given implementation
71      *
72      * @throws Doctrine_Tree_Exception          if table attributes have not been defined
73      */
74     public function setTableDefinition()
75     {
76         throw new Doctrine_Tree_Exception('Table attributes have not been defined for this Tree implementation.');
77     }
78
79     /**
80      * this method is used for setting up relations and attributes and should be used by specific implementations
81      *
82      */
83     public function setUp()
84     {
85     }
86
87     /**
88      * factory method to return tree instance based upon chosen implementation
89      *
90      * @param object $table                     instance of Doctrine_Table
91      * @param string $impName                   implementation (NestedSet, AdjacencyList, MaterializedPath)
92      * @param array $options                    options
93      * @return object $options                  instance of Doctrine_Node
94      * @throws Doctrine_Exception               if class does not extend Doctrine_Tree
95      */
96     public static function factory(Doctrine_Table $table, $implName, $options = array())
97     {
98         $class = 'Doctrine_Tree_' . $implName;
99         if ( ! class_exists($class)) {
100             throw new Doctrine_Exception('The chosen class must extend Doctrine_Tree');
101         }
102         return new $class($table, $options);
103     }
104
105     /**
106      * gets tree attribute value
107      *        
108      */     
109     public function getAttribute($name)
110     {
111       return isset($this->options[$name]) ? $this->options[$name] : null;
112     }
113
114     /**
115      * sets tree attribute value
116      *
117      * @param mixed            
118      */
119     public function setAttribute($name, $value)
120     {
121       $this->options[$name] = $value;
122     }
123
124     /**
125      * Returns the base tree component.
126      */
127     public function getBaseComponent()
128     {
129         return $this->_baseComponent;
130     }
131 }