Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Tree.php 7490 2010-03-29 19:53:27Z 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.doctrine-project.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.doctrine-project.org
29
 * @since       1.0
30
 * @version     $Revision: 7490 $
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 create a Tree.
89
     *
90
     * This is a factory method that returns a tree instance based upon
91
     * chosen implementation.
92
     *
93
     * @param object $table                     instance of Doctrine_Table
94
     * @param string $impName                   implementation (NestedSet, AdjacencyList, MaterializedPath)
95
     * @param array $options                    options
96
     * @return Doctrine_Tree
97
     * @throws Doctrine_Exception               if class $implName does not extend Doctrine_Tree
98
     */
99
    public static function factory(Doctrine_Table $table, $implName, $options = array())
100
    {
101
        $class = 'Doctrine_Tree_' . $implName;
102
        if ( ! class_exists($class)) {
103
            throw new Doctrine_Exception('The chosen class must extend Doctrine_Tree');
104
        }
105
        return new $class($table, $options);
106
    }
107
 
108
    /**
109
     * gets tree attribute value
110
     *
111
     */
112
    public function getAttribute($name)
113
    {
114
      return isset($this->options[$name]) ? $this->options[$name] : null;
115
    }
116
 
117
    /**
118
     * sets tree attribute value
119
     *
120
     * @param mixed
121
     */
122
    public function setAttribute($name, $value)
123
    {
124
      $this->options[$name] = $value;
125
    }
126
 
127
    /**
128
     * Returns the base tree component.
129
     */
130
    public function getBaseComponent()
131
    {
132
        return $this->_baseComponent;
133
    }
134
}