Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 22 |
CRAP | |
0.00% |
0 / 1 |
Codex | |
0.00% |
0 / 22 |
|
0.00% |
0 / 22 |
506 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
accordion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
button | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
card | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkbox | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
field | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
htmlSnippet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
infoChip | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
label | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
message | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
option | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
pager | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
progressBar | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
radio | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
select | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
tab | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
table | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
tabs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
textArea | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
textInput | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
thumbnail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toggleSwitch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Codex.php |
4 | * |
5 | * This class provides factory methods to create instances of various builders, |
6 | * including Accordion, Button, Card, Checkbox, and others. These builders facilitate |
7 | * the creation of standardized UI components adhering to the Codex design principles. |
8 | * |
9 | * Each builder follows the builder pattern, allowing for easy and fluent creation |
10 | * and customization of components used across Wikimedia projects. |
11 | * |
12 | * @category Utility |
13 | * @package Codex\Utility |
14 | * @since 0.1.0 |
15 | * @author Doğu Abaris <abaris@null.net> |
16 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
17 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
18 | */ |
19 | |
20 | namespace Wikimedia\Codex\Utility; |
21 | |
22 | use Wikimedia\Codex\Builder\AccordionBuilder; |
23 | use Wikimedia\Codex\Builder\ButtonBuilder; |
24 | use Wikimedia\Codex\Builder\CardBuilder; |
25 | use Wikimedia\Codex\Builder\CheckboxBuilder; |
26 | use Wikimedia\Codex\Builder\FieldBuilder; |
27 | use Wikimedia\Codex\Builder\HtmlSnippetBuilder; |
28 | use Wikimedia\Codex\Builder\InfoChipBuilder; |
29 | use Wikimedia\Codex\Builder\LabelBuilder; |
30 | use Wikimedia\Codex\Builder\MessageBuilder; |
31 | use Wikimedia\Codex\Builder\OptionBuilder; |
32 | use Wikimedia\Codex\Builder\PagerBuilder; |
33 | use Wikimedia\Codex\Builder\ProgressBarBuilder; |
34 | use Wikimedia\Codex\Builder\RadioBuilder; |
35 | use Wikimedia\Codex\Builder\SelectBuilder; |
36 | use Wikimedia\Codex\Builder\TabBuilder; |
37 | use Wikimedia\Codex\Builder\TableBuilder; |
38 | use Wikimedia\Codex\Builder\TabsBuilder; |
39 | use Wikimedia\Codex\Builder\TextAreaBuilder; |
40 | use Wikimedia\Codex\Builder\TextInputBuilder; |
41 | use Wikimedia\Codex\Builder\ThumbnailBuilder; |
42 | use Wikimedia\Codex\Builder\ToggleSwitchBuilder; |
43 | use Wikimedia\Codex\Infrastructure\CodexServices; |
44 | |
45 | /** |
46 | * Codex UI |
47 | * |
48 | * This class provides methods for creating instances of various builders, each |
49 | * corresponding to a UI component in the Codex design system. These builders allow |
50 | * the creation and customization of Codex components. |
51 | * |
52 | * @category Utility |
53 | * @package Codex\Utility |
54 | * @since 0.1.0 |
55 | * @author Doğu Abaris <abaris@null.net> |
56 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
57 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
58 | */ |
59 | class Codex { |
60 | |
61 | /** |
62 | * The CodexServices instance that manages services. |
63 | */ |
64 | private CodexServices $services; |
65 | |
66 | /** |
67 | * Constructor initializes CodexServices. |
68 | * |
69 | * @since 0.1.0 |
70 | */ |
71 | public function __construct() { |
72 | $this->services = CodexServices::getInstance(); |
73 | } |
74 | |
75 | /** |
76 | * Resolves and returns the Accordion builder. |
77 | * |
78 | * @since 0.1.0 |
79 | * @return AccordionBuilder The Accordion builder instance. |
80 | */ |
81 | public function accordion(): AccordionBuilder { |
82 | return $this->services->getService( 'AccordionBuilder' ); |
83 | } |
84 | |
85 | /** |
86 | * Resolves and returns the Button builder. |
87 | * |
88 | * @since 0.1.0 |
89 | * @return ButtonBuilder The Button builder instance. |
90 | */ |
91 | public function button(): ButtonBuilder { |
92 | return $this->services->getService( 'ButtonBuilder' ); |
93 | } |
94 | |
95 | /** |
96 | * Resolves and returns the Card builder. |
97 | * |
98 | * @since 0.1.0 |
99 | * @return CardBuilder The Card builder instance. |
100 | */ |
101 | public function card(): CardBuilder { |
102 | return $this->services->getService( 'CardBuilder' ); |
103 | } |
104 | |
105 | /** |
106 | * Resolves and returns the Checkbox builder. |
107 | * |
108 | * @since 0.1.0 |
109 | * @return CheckboxBuilder The Checkbox builder instance. |
110 | */ |
111 | public function checkbox(): CheckboxBuilder { |
112 | return $this->services->getService( 'CheckboxBuilder' ); |
113 | } |
114 | |
115 | /** |
116 | * Resolves and returns the Field builder. |
117 | * |
118 | * @since 0.1.0 |
119 | * @return FieldBuilder The Field builder instance. |
120 | */ |
121 | public function field(): FieldBuilder { |
122 | return $this->services->getService( 'FieldBuilder' ); |
123 | } |
124 | |
125 | /** |
126 | * Resolves and returns the HtmlSnippet. |
127 | * |
128 | * @since 0.1.0 |
129 | * @return HtmlSnippetBuilder The HtmlSnippet instance. |
130 | */ |
131 | public function htmlSnippet(): HtmlSnippetBuilder { |
132 | return $this->services->getService( 'HtmlSnippetBuilder' ); |
133 | } |
134 | |
135 | /** |
136 | * Resolves and returns the InfoChip builder. |
137 | * |
138 | * @since 0.1.0 |
139 | * @return InfoChipBuilder The InfoChip builder instance. |
140 | */ |
141 | public function infoChip(): InfoChipBuilder { |
142 | return $this->services->getService( 'InfoChipBuilder' ); |
143 | } |
144 | |
145 | /** |
146 | * Resolves and returns the Label builder. |
147 | * |
148 | * @since 0.1.0 |
149 | * @return LabelBuilder The Label builder instance. |
150 | */ |
151 | public function label(): LabelBuilder { |
152 | return $this->services->getService( 'LabelBuilder' ); |
153 | } |
154 | |
155 | /** |
156 | * Resolves and returns the Message builder. |
157 | * |
158 | * @since 0.1.0 |
159 | * @return MessageBuilder The Message builder instance. |
160 | */ |
161 | public function message(): MessageBuilder { |
162 | return $this->services->getService( 'MessageBuilder' ); |
163 | } |
164 | |
165 | /** |
166 | * Resolves and returns the Option builder. |
167 | * |
168 | * @since 0.1.0 |
169 | * @return OptionBuilder The Option builder instance. |
170 | */ |
171 | public function option(): OptionBuilder { |
172 | return $this->services->getService( 'OptionBuilder' ); |
173 | } |
174 | |
175 | /** |
176 | * Resolves and returns the Pager builder. |
177 | * |
178 | * @since 0.1.0 |
179 | * @return PagerBuilder The Pager builder instance. |
180 | */ |
181 | public function pager(): PagerBuilder { |
182 | return $this->services->getService( 'PagerBuilder' ); |
183 | } |
184 | |
185 | /** |
186 | * Resolves and returns the ProgressBar builder. |
187 | * |
188 | * @since 0.1.0 |
189 | * @return ProgressBarBuilder The ProgressBar builder instance. |
190 | */ |
191 | public function progressBar(): ProgressBarBuilder { |
192 | return $this->services->getService( 'ProgressBarBuilder' ); |
193 | } |
194 | |
195 | /** |
196 | * Resolves and returns the Radio builder. |
197 | * |
198 | * @since 0.1.0 |
199 | * @return RadioBuilder The Radio builder instance. |
200 | */ |
201 | public function radio(): RadioBuilder { |
202 | return $this->services->getService( 'RadioBuilder' ); |
203 | } |
204 | |
205 | /** |
206 | * Resolves and returns the Select builder. |
207 | * |
208 | * @since 0.1.0 |
209 | * @return SelectBuilder The Select builder instance. |
210 | */ |
211 | public function select(): SelectBuilder { |
212 | return $this->services->getService( 'SelectBuilder' ); |
213 | } |
214 | |
215 | /** |
216 | * Resolves and returns the Tab builder. |
217 | * |
218 | * @since 0.1.0 |
219 | * @return TabBuilder The Tab builder instance. |
220 | */ |
221 | public function tab(): TabBuilder { |
222 | return $this->services->getService( 'TabBuilder' ); |
223 | } |
224 | |
225 | /** |
226 | * Resolves and returns the Table builder. |
227 | * |
228 | * @since 0.1.0 |
229 | * @return TableBuilder The Table builder instance. |
230 | */ |
231 | public function table(): TableBuilder { |
232 | return $this->services->getService( 'TableBuilder' ); |
233 | } |
234 | |
235 | /** |
236 | * Resolves and returns the Tabs builder. |
237 | * |
238 | * @since 0.1.0 |
239 | * @return TabsBuilder The Tabs builder instance. |
240 | */ |
241 | public function tabs(): TabsBuilder { |
242 | return $this->services->getService( 'TabsBuilder' ); |
243 | } |
244 | |
245 | /** |
246 | * Resolves and returns the TextArea builder. |
247 | * |
248 | * @since 0.1.0 |
249 | * @return TextAreaBuilder The TextArea builder instance. |
250 | */ |
251 | public function textArea(): TextAreaBuilder { |
252 | return $this->services->getService( 'TextAreaBuilder' ); |
253 | } |
254 | |
255 | /** |
256 | * Resolves and returns the TextInput builder. |
257 | * |
258 | * @since 0.1.0 |
259 | * @return TextInputBuilder The TextInput builder instance. |
260 | */ |
261 | public function textInput(): TextInputBuilder { |
262 | return $this->services->getService( 'TextInputBuilder' ); |
263 | } |
264 | |
265 | /** |
266 | * Resolves and returns the Thumbnail builder. |
267 | * |
268 | * @since 0.1.0 |
269 | * @return ThumbnailBuilder The Thumbnail builder instance. |
270 | */ |
271 | public function thumbnail(): ThumbnailBuilder { |
272 | return $this->services->getService( 'ThumbnailBuilder' ); |
273 | } |
274 | |
275 | /** |
276 | * Resolves and returns the ToggleSwitch builder. |
277 | * |
278 | * @since 0.1.0 |
279 | * @return ToggleSwitchBuilder The ToggleSwitch builder instance. |
280 | */ |
281 | public function toggleSwitch(): ToggleSwitchBuilder { |
282 | return $this->services->getService( 'ToggleSwitchBuilder' ); |
283 | } |
284 | } |