1: <?php
2: /**
3: * The Horde_Tree:: class provides a tree view of hierarchical information. It
4: * allows for expanding/collapsing of branches.
5: *
6: * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Marko Djukic <marko@oblo.com>
12: * @author Michael Slusarz <slusarz@horde.org>
13: * @category Horde
14: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15: * @package Tree
16: */
17: class Horde_Tree
18: {
19: /* Display extra columns. */
20: const EXTRA_LEFT = 0;
21: const EXTRA_RIGHT = 1;
22:
23: /**
24: * The preceding text, before the Horde_Tree instance name, used for
25: * collapse/expand submissions.
26: */
27: const TOGGLE = 'ht_toggle_';
28:
29: /**
30: * Attempts to return a concrete instance.
31: *
32: * @param string $name The name of this tree instance.
33: * @param string $renderer Either the tree renderer driver or a full
34: * class name to use.
35: * @param array $params Any additional parameters the constructor
36: * needs.
37: *
38: * @return Horde_Tree The newly created concrete instance.
39: * @throws Horde_Tree_Exception
40: */
41: static public function factory($name, $renderer, $params = array())
42: {
43: $ob = null;
44:
45: /* Base drivers (in Tree/ directory). */
46: $class = __CLASS__ . '_' . ucfirst($renderer);
47: if (class_exists($class)) {
48: $ob = new $class($name, $params);
49: } else {
50: /* Explicit class name, */
51: $class = $renderer;
52: if (class_exists($class)) {
53: $ob = new $class($name, $params);
54: }
55: }
56:
57: if ($ob) {
58: if ($ob->isSupported()) {
59: return $ob;
60: }
61:
62: return self::factory($name, $ob->fallback(), $params);
63: }
64:
65: throw new Horde_Tree_Exception(__CLASS__ . ' renderer not found: ' . $renderer);
66: }
67:
68: }
69: