1 | <?php |
||
44 | abstract class Element |
||
45 | { |
||
46 | const SCOPE_ELEMENT = ""; |
||
47 | const SCOPE_WRAPPER = "_wrapper"; |
||
48 | |||
49 | /** |
||
50 | * The id of the form useful for CSS styling and DOM access. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $id; |
||
55 | |||
56 | /** |
||
57 | * The label of the form element. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $label; |
||
62 | |||
63 | /** |
||
64 | * The description of the form element. |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $description; |
||
69 | |||
70 | /** |
||
71 | * An array of all the CSS classes associated with this element. |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $classes = array(); |
||
76 | |||
77 | /** |
||
78 | * An array of all HTML attributes. These attributes are stored as |
||
79 | * objects of the Attribute class. Attributes in this array are applied |
||
80 | * directly to the form element. |
||
81 | * |
||
82 | * @var array |
||
83 | */ |
||
84 | protected $attributes = array(); |
||
85 | |||
86 | /** |
||
87 | * An array of all HTML attributes. These attributes are stored as |
||
88 | * objects of the Attribute class. Attributes in this array are applied |
||
89 | * directly to the wrapper which wraps the form element. |
||
90 | * |
||
91 | * @var array |
||
92 | */ |
||
93 | protected $wrapperAttributes = array(); |
||
94 | |||
95 | /** |
||
96 | * An array of all error messages associated with this element. |
||
97 | * Error messages are setup during validation, when any element |
||
98 | * fails its validation test. |
||
99 | * |
||
100 | * @var array |
||
101 | */ |
||
102 | protected $errors = array(); |
||
103 | |||
104 | /** |
||
105 | * A boolean value which is set to true whenever there is an error |
||
106 | * assiciated with the field element in one way or the other. |
||
107 | */ |
||
108 | protected $error; |
||
109 | |||
110 | /** |
||
111 | * The parent element which contains this element. |
||
112 | * @var Element |
||
113 | */ |
||
114 | protected $parent = null; |
||
115 | |||
116 | protected $name; |
||
117 | |||
118 | protected $renderLabel = true; |
||
119 | |||
120 | protected $templateRenderer; |
||
121 | |||
122 | public function __construct($label="", $description="", $id="") |
||
128 | |||
129 | public function setId($id) |
||
135 | |||
136 | public function getId() |
||
140 | |||
141 | /** |
||
142 | * Public accessor for setting the name property of the field. |
||
143 | * |
||
144 | * @param $name The name to assign to the form element. |
||
145 | * @return Element |
||
146 | */ |
||
147 | public function setName($name) |
||
152 | |||
153 | /** |
||
154 | * Public accessor for getting the name property of the field. |
||
155 | * |
||
156 | * @return The name of the form field. |
||
|
|||
157 | */ |
||
158 | public function getName() |
||
162 | |||
163 | //! Sets the label which is attached to this element. |
||
164 | public function setLabel($label) |
||
169 | |||
170 | //! Gets the label which is attached to this element. |
||
171 | public function getLabel() |
||
175 | |||
176 | /** |
||
177 | * Gets the description which is attached to this element. The description |
||
178 | * is normally displayed under the element when rendering HTML. |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getDescription() |
||
186 | |||
187 | /** |
||
188 | * Sets the description which is attached to this element. The description |
||
189 | * is normally displayed under the element when rendering HTML. |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | public function setDescription($description) |
||
198 | |||
199 | /** |
||
200 | * Returns all the arrays associated with this document. |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | public function getErrors() |
||
208 | |||
209 | // Returns the error flag for this element. |
||
210 | public function hasError() |
||
214 | |||
215 | public function getType() |
||
219 | |||
220 | /** |
||
221 | * Renders the form element by outputing the HTML associated with |
||
222 | * the element. This method is abstract and it is implemented by |
||
223 | * all the other classes which inherit the Element class. |
||
224 | */ |
||
225 | abstract public function render(); |
||
226 | |||
227 | public function __toString() |
||
231 | |||
232 | //! Returns an array of all the CSS classes associated with this |
||
233 | //! element. |
||
234 | public function getCSSClasses() |
||
238 | |||
239 | //! Adds a css class to this element. |
||
240 | public function addCSSClass($class) |
||
245 | |||
246 | //! Adds an attribute to the list of attributes of this element. |
||
247 | //! This method internally creates a new Attribute object and appends |
||
248 | //! it to the list of attributes. |
||
249 | //! \see Attribute |
||
250 | public function setAttribute($attribute,$value,$scope = Element::SCOPE_ELEMENT) |
||
263 | |||
264 | /** |
||
265 | * Returns an HTML representation of all the attributes. This method is |
||
266 | * normally called when rendering the HTML for the element. |
||
267 | */ |
||
268 | public function getAttributes($scope=Element::SCOPE_ELEMENT) |
||
278 | |||
279 | public function getAttribute($attribute, $scope = Element::SCOPE_ELEMENT) |
||
284 | |||
285 | public function setErrors($errors) |
||
290 | |||
291 | public function getRenderLabel() |
||
295 | |||
296 | public function setRenderLabel($renderLabel) |
||
300 | |||
301 | public function setTemplateRenderer($templateRenderer) |
||
305 | } |
||
306 | |||
307 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.