1: <?php
2: /**
3: * The Horde_Core_Ui_VarRenderer:: class provides base functionality for
4: * other Horde UI elements.
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 Jason M. Felice <jason.m.felice@gmail.com>
12: * @category Horde
13: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
14: * @package Core
15: */
16: class Horde_Core_Ui_VarRenderer
17: {
18: /**
19: * Parameters which change this renderer's behavior.
20: *
21: * @var array
22: */
23: protected $_params;
24:
25: /**
26: * Constructs a new renderer.
27: *
28: * @param array $params The name of the variable which will track this UI
29: * widget's state.
30: */
31: public function __construct($params = array())
32: {
33: $this->_params = $params;
34: }
35:
36: /**
37: * Constructs a new instance.
38: *
39: * @param mixed $driver This is the renderer subclass we will instantiate.
40: * If an array is passed, the first element is the
41: * library path and the second element is the driver
42: * name.
43: * @param array $params Parameters specific to the subclass.
44: *
45: * @return Horde_Core_Ui_VarRenderer A subclass instance.
46: * @throws Horde_Exception
47: */
48: static public function factory($driver, $params = array())
49: {
50: if (is_array($driver)) {
51: $app = $driver[0];
52: $driver = $driver[1];
53: }
54:
55: $driver = ucfirst(basename($driver));
56: if (!empty($app)) {
57: include_once $GLOBALS['registry']->get('fileroot', $app) . '/lib/Ui/VarRenderer/' . $driver . '.php';
58: }
59:
60: $class = __CLASS__ . '_' . $driver;
61: if (!class_exists($class)) {
62: throw new Horde_Exception('Class definition of ' . $class . ' not found.');
63: }
64:
65: return new $class($params);
66: }
67:
68: /**
69: * Renders a variable.
70: *
71: * @param Horde_Form $form A Horde_Form instance,
72: * or null if none is available.
73: * @param Horde_Form_Variable $va r A Horde_Form_Variable.
74: * @param Variables $vars A Horde_Variables instance.
75: * @param boolean $isInput Whether this is an input field.
76: */
77: public function render($form, $var, $vars, $isInput = false)
78: {
79: $state = $isInput ? 'Input' : 'Display';
80: $method = "_renderVar${state}_" . $var->type->getTypeName();
81: if (!method_exists($this, $method)) {
82: $method = "_renderVar${state}Default";
83: }
84:
85: return $this->$method($form, $var, $vars);
86: }
87:
88: /**
89: * Finishes rendering after all fields are output.
90: *
91: * @return string TODO
92: */
93: public function renderEnd()
94: {
95: return '';
96: }
97: }
98: