File: VarRenderer.php

package info (click to toggle)
horde3 3.1.3-4etch7
  • links: PTS
  • area: main
  • in suites: etch
  • size: 22,876 kB
  • ctags: 18,071
  • sloc: php: 75,151; xml: 2,979; sql: 1,069; makefile: 79; sh: 64
file content (139 lines) | stat: -rw-r--r-- 4,241 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
 * The Horde_UI_VarRenderer:: class provides base functionality for
 * other Horde UI elements.
 *
 * $Horde: framework/UI/UI/VarRenderer.php,v 1.12.10.10 2006/06/20 09:08:45 jan Exp $
 *
 * Copyright 2003-2006 Jason M. Felice <jfelice@cronosys.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @since   Horde_UI 0.0.1
 * @package Horde_UI
 */
class Horde_UI_VarRenderer {

    /**
     * Parameters which change this renderer's behavior.
     *
     * @var array
     */
    var $_params;

    /**
     * Charset to use for output.
     *
     * @var string
     */
    var $_charset;

    /**
     * Constructs a new renderer.
     *
     * @param array $params  The name of the variable which will track this UI
     *                       widget's state.
     */
    function Horde_UI_VarRenderer($params = array())
    {
        $this->_params = $params;
        $this->_charset = NLS::getCharset();
    }

    /**
     * Constructs a new Horde_UI_VarRenderer:: instance.
     *
     * @param mixed $driver  This is the renderer subclass we will instantiate.
     *                       If an array is passed, the first element is the
     *                       library path and the second element is the driver
     *                       name.
     * @param array $params  Parameters specific to the subclass.
     *
     * @return Horde_UI_VarRenderer  A Horde_UI_VarRenderer:: subclass
     *                               instance.
     */
    function &factory($driver, $params = array())
    {
        if (is_array($driver)) {
            $app = $driver[0];
            $driver = $driver[1];
        }

        $driver = basename($driver);

        if (!empty($app)) {
            require_once $GLOBALS['registry']->get('fileroot', $app) . '/lib/UI/VarRenderer/' . $driver . '.php';
        } elseif (@file_exists(dirname(__FILE__) . '/VarRenderer/' . $driver . '.php')) {
            require_once dirname(__FILE__) . '/VarRenderer/' . $driver . '.php';
        } else {
            @include_once 'Horde/UI/VarRenderer/' . $driver . '.php';
        }

        $class = 'Horde_UI_VarRenderer_' . $driver;
        if (class_exists($class)) {
            $vr = &new $class($params);
        } else {
            $vr = PEAR::raiseError('Class definition of ' . $class . ' not found.');
        }

        return $vr;
    }

    /**
     * Returns a Horde_UI_VarRenderer:: instance, constructing one with the
     * specified parameters if necessary.
     *
     * @param string $driver  This is the renderer subclass we will
     *                        instantiate.
     * @param array $params   Parameters specific to the subclass.
     *
     * @return Horde_UI_VarRenderer  A Horde_UI_VarRenderer:: subclass
     *                               instance.
     */
    function &singleton($driver, $params = array())
    {
        static $cache;

        if (is_null($driver)) {
            $class = 'Horde_UI_VarRenderer';
        }
        $key = serialize(array ($driver, $params));
        if (!isset($cache[$key])) {
            $cache[$key] = &Horde_UI_VarRenderer::factory($driver, $params);
        }
        return $cache[$key];
    }

    /**
     * Renders a variable.
     *
     * @param Horde_Form &$form           Reference to a Horde_Form instance,
     *                                    or null if none is available.
     * @param Horde_Form_Variable &$var   Reference to a Horde_Form_Variable.
     * @param Variables &$vars            A Variables instance.
     * @param boolean $isInput            Whether this is an input field.
     */
    function render(&$form, &$var, &$vars, $isInput = false)
    {
        if ($isInput) {
            $state = 'Input';
        } else {
            $state = 'Display';
        }
        $method = "_renderVar${state}_" . $var->type->getTypeName();
        if (!@method_exists($this, $method)) {
            $method = "_renderVar${state}Default";
        }
        return $this->$method($form, $var, $vars);
    }

    /**
     * Finishes rendering after all fields are output.
     */
    function renderEnd()
    {
        return '';
    }

}