1 | <?php |
||
44 | abstract class Element |
||
45 | { |
||
46 | const SCOPE_ELEMENT = ""; |
||
47 | const SCOPE_WRAPPER = "_wrapper"; |
||
48 | |||
49 | protected $formId; |
||
50 | |||
51 | /** |
||
52 | * The id of the form useful for CSS styling and DOM access. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $id; |
||
57 | |||
58 | /** |
||
59 | * The label of the form element. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $label; |
||
64 | |||
65 | /** |
||
66 | * The description of the form element. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $description; |
||
71 | |||
72 | /** |
||
73 | * An array of all the CSS classes associated with this element. |
||
74 | * |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $classes = array(); |
||
78 | |||
79 | /** |
||
80 | * An array of all HTML attributes. These attributes are stored as |
||
81 | * objects of the Attribute class. Attributes in this array are applied |
||
82 | * directly to the form element. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $attributes = array(); |
||
87 | |||
88 | /** |
||
89 | * An array of all HTML attributes. These attributes are stored as |
||
90 | * objects of the Attribute class. Attributes in this array are applied |
||
91 | * directly to the wrapper which wraps the form element. |
||
92 | * |
||
93 | * @var array |
||
94 | */ |
||
95 | protected $wrapperAttributes = array(); |
||
96 | |||
97 | /** |
||
98 | * An array of all error messages associated with this element. |
||
99 | * Error messages are setup during validation, when any element |
||
100 | * fails its validation test. |
||
101 | * |
||
102 | * @var array |
||
103 | */ |
||
104 | protected $errors = array(); |
||
105 | |||
106 | /** |
||
107 | * A boolean value which is set to true whenever there is an error |
||
108 | * assiciated with the field element in one way or the other. |
||
109 | */ |
||
110 | protected $error; |
||
111 | |||
112 | /** |
||
113 | * The parent element which contains this element. |
||
114 | * @var Element |
||
115 | */ |
||
116 | protected $parent = null; |
||
117 | |||
118 | /** |
||
119 | * The name of the form field. This is what is to be outputed as |
||
120 | * the HTML name attribute of the field. If name encryption is |
||
121 | * enabled the outputed name to HTML is mangled by the encryption |
||
122 | * algorithm. However internally the Field may still be referenced |
||
123 | * bu the unmangled name. |
||
124 | */ |
||
125 | public $name; |
||
126 | |||
127 | protected $renderLabel = true; |
||
128 | |||
129 | 14 | public function __construct($label="", $description="", $id="") |
|
135 | |||
136 | 14 | public function setId($id) |
|
142 | |||
143 | 9 | public function getId() |
|
147 | |||
148 | /** |
||
149 | * Public accessor for setting the name property of the field. |
||
150 | * |
||
151 | * @param $name The name to assign to the form element. |
||
152 | */ |
||
153 | 1 | public function setName($name) |
|
158 | |||
159 | /** |
||
160 | * Public accessor for getting the name property of the field. |
||
161 | * |
||
162 | * @return The name of the form field. |
||
|
|||
163 | */ |
||
164 | 9 | public function getName() |
|
168 | |||
169 | //! Sets the label which is attached to this element. |
||
170 | 14 | public function setLabel($label) |
|
175 | |||
176 | //! Gets the label which is attached to this element. |
||
177 | 9 | public function getLabel() |
|
181 | |||
182 | /** |
||
183 | * Gets the description which is attached to this element. The description |
||
184 | * is normally displayed under the element when rendering HTML. |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | 9 | public function getDescription() |
|
192 | |||
193 | /** |
||
194 | * Sets the description which is attached to this element. The description |
||
195 | * is normally displayed under the element when rendering HTML. |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | 14 | public function setDescription($description) |
|
204 | |||
205 | /** |
||
206 | * Returns all the arrays associated with this document. |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | 1 | public function getErrors() |
|
214 | |||
215 | // Returns the error flag for this element. |
||
216 | 9 | public function hasError() |
|
220 | |||
221 | 1 | public function getType() |
|
225 | |||
226 | /** |
||
227 | * Renders the form element by outputing the HTML associated with |
||
228 | * the element. This method is abstract and it is implemented by |
||
229 | * all the other classes which inherit the Element class. |
||
230 | */ |
||
231 | abstract public function render(); |
||
232 | |||
233 | 9 | public function __toString() |
|
237 | |||
238 | //! Returns an array of all the CSS classes associated with this |
||
239 | //! element. |
||
240 | 9 | public function getCSSClasses() |
|
244 | |||
245 | //! Adds a css class to this element. |
||
246 | 1 | public function addCSSClass($class) |
|
251 | |||
252 | //! Adds an attribute to the list of attributes of this element. |
||
253 | //! This method internally creates a new Attribute object and appends |
||
254 | //! it to the list of attributes. |
||
255 | //! \see Attribute |
||
256 | 14 | public function setAttribute($attribute,$value,$scope = Element::SCOPE_ELEMENT) |
|
257 | { |
||
258 | // Force the setting of the attribute. |
||
259 | 14 | if($scope == Element::SCOPE_ELEMENT) |
|
260 | { |
||
261 | 14 | $this->attributes[$attribute] = $value; |
|
262 | } |
||
263 | else if($scope == Element::SCOPE_WRAPPER) |
||
264 | { |
||
265 | $this->wrapperAttributes[$attribute] = $value; |
||
266 | } |
||
267 | 14 | return $this; |
|
268 | } |
||
269 | |||
270 | /** |
||
271 | * Returns an HTML representation of all the attributes. This method is |
||
272 | * normally called when rendering the HTML for the element. |
||
273 | */ |
||
274 | 12 | public function getAttributes($scope=Element::SCOPE_ELEMENT) |
|
284 | |||
285 | 9 | public function getAttribute($attribute, $scope = Element::SCOPE_ELEMENT) |
|
290 | |||
291 | 4 | public function setErrors($errors) |
|
296 | |||
297 | 9 | public function getRenderLabel() |
|
301 | |||
302 | 1 | public function setRenderLabel($renderLabel) |
|
306 | |||
307 | 9 | public function isContainer() |
|
311 | } |
||
312 | |||
313 |
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.