1 | <?php |
||
5 | abstract class Component |
||
6 | { |
||
7 | |||
8 | const RM_NONE = 'none'; |
||
9 | const RM_HIDDENFIELD = 'hidden'; |
||
10 | const RM_DEFAULT = 'default'; |
||
11 | |||
12 | protected |
||
13 | $parent, |
||
14 | $children = array(), |
||
15 | $customAttributes = array(); |
||
16 | private |
||
17 | $slug, |
||
18 | $active = true, |
||
19 | $customClasses = array(); |
||
20 | |||
21 | public function __construct ($slug) |
||
25 | |||
26 | /** |
||
27 | * Resets the component |
||
28 | */ |
||
29 | public function reset () |
||
35 | |||
36 | /** |
||
37 | * Gets the HTML markup of the component |
||
38 | * |
||
39 | * @param bool $showLabel |
||
40 | * |
||
41 | * @return mixed |
||
42 | */ |
||
43 | public abstract function getHTML ($showLabel = true); |
||
44 | |||
45 | /** |
||
46 | * Echoes the HTML markup of the component |
||
47 | * @return $this |
||
48 | */ |
||
49 | public final function output () |
||
54 | |||
55 | public abstract function isValid (); |
||
56 | |||
57 | public function isVisible () |
||
61 | |||
62 | protected function add (Component $component) |
||
66 | |||
67 | public function renderWhenHidden () |
||
71 | |||
72 | public function renderHiddenField () |
||
76 | |||
77 | protected function getCustomClasses () |
||
81 | |||
82 | /** |
||
83 | * Adds component to given parent component |
||
84 | * |
||
85 | * @param Component $parent |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function addTo (Component $parent) |
||
95 | |||
96 | /** |
||
97 | * Adds class(es) to this component's node |
||
98 | * |
||
99 | * @param string|array $class |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | public function addClass ($class) |
||
112 | |||
113 | /** |
||
114 | * Sets a custom attribute |
||
115 | * |
||
116 | * @param string $attr Attribute name |
||
117 | * @param string $value Attribtue value |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function attr ($attr, $value) |
||
126 | |||
127 | /** |
||
128 | * Sets whether the component is active |
||
129 | * |
||
130 | * @param boolean $active |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function setActive ($active = true) |
||
139 | |||
140 | /** |
||
141 | * Checks whether the component is active |
||
142 | * @return boolean |
||
143 | */ |
||
144 | public function isActive () |
||
148 | |||
149 | /** |
||
150 | * Returns a flat list of the component's enabled children |
||
151 | * |
||
152 | * @param boolean $recursive |
||
153 | * @param boolean $includeInactiveFields whether to include inactive fields |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | public function getChildren ($recursive = true, $includeInactiveFields = false) |
||
169 | |||
170 | /** |
||
171 | * Check if given component is child |
||
172 | * |
||
173 | * @param Component $child component to search for |
||
174 | * @param boolean $recursive whether or not to search recursively |
||
175 | * |
||
176 | * @return boolean |
||
177 | */ |
||
178 | public function hasChild ($child, $recursive = true) |
||
186 | |||
187 | /** |
||
188 | * Gets all HTML attributes |
||
189 | * @return array array of attributes |
||
190 | */ |
||
191 | public function getAttributes () |
||
196 | |||
197 | /** |
||
198 | * Gets all HTML attributes |
||
199 | * @return string attributes as string |
||
200 | */ |
||
201 | public function getAttributesString () |
||
208 | |||
209 | /** |
||
210 | * Gets HTML class attribute |
||
211 | * @return array array of classes |
||
212 | */ |
||
213 | public function getClasses () |
||
219 | |||
220 | public function getLocalSlug () |
||
224 | |||
225 | public function getGlobalSlug () |
||
232 | |||
233 | /** |
||
234 | * Gets an array of the custom classes, each of them prefixed with wrap- |
||
235 | * @return array |
||
236 | */ |
||
237 | public function getWrapperClasses () |
||
244 | |||
245 | /** |
||
246 | * @return Component |
||
247 | */ |
||
248 | public function getRoot () |
||
255 | |||
256 | } |