ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ComponentEntry.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use JsonSerializable;
24
30class ComponentEntry extends AbstractEntryPart implements JsonSerializable
31{
32 protected const DEPTH_FROM_REPOSITORY_ROOT = 8;
33
37 protected array $children = array();
38
39 protected string $id = "";
40 protected string $title = "";
41 protected bool $is_abstract = false;
42 protected array $status_list_entry = array("Accepted", "Proposed", "To be revised");
43 protected array $status_list_implementation = array("Implemented", "Partly implemented", "To be implemented");
44 protected string $status_entry = "";
45 protected string $status_implementation = "";
47 protected string $background = "";
48 protected array $context = [];
49 protected string $selector = "";
50 protected array $feature_wiki_references = array();
51 protected ?ComponentEntryRules $rules = null;
52 protected ?string $parent = null;
53 protected array $less_variables = array();
54 protected string $path = "";
55 protected array $examples = [];
56 protected string $examples_path = "";
57 protected string $examples_namespace = "";
58 protected string $namesapce = "";
59 protected string $ilias_root;
60
61 public function __construct($entry_data)
62 {
64 $this->ilias_root = dirname(__FILE__, self::DEPTH_FROM_REPOSITORY_ROOT);
65 $this->assert()->isIndex('id', $entry_data);
66 $this->setId($entry_data['id']);
67 $this->assert()->isIndex('title', $entry_data);
68 $this->setTitle($entry_data['title']);
69 $this->assert()->isIndex('namespace', $entry_data);
70 $this->setNamespace($entry_data['namespace']);
71 $this->setIsAbstract((bool) $entry_data['abstract']);
72 $this->setStatusEntry("Proposed");
73 $this->setStatusImplementation("Partly implemented");
74 if (array_key_exists('description', $entry_data)) {
75 $this->setDescription(new ComponentEntryDescription($entry_data['description']));
76 }
77 if (array_key_exists('rules', $entry_data) && is_array($entry_data['rules'])) {
78 $this->setRules(new ComponentEntryRules($entry_data['rules']));
79 }
80
81 $this->assert()->isIndex('path', $entry_data);
82 $this->setPath($entry_data['path']);
83
84 if (array_key_exists('background', $entry_data)) {
85 $this->setBackground($entry_data['background']);
86 }
87 if (array_key_exists('context', $entry_data)) {
88 $this->setContext($entry_data['context']);
89 }
90 if (array_key_exists('featurewiki', $entry_data)) {
91 $this->setFeatureWikiReferences($entry_data['featurewiki']);
92 }
93 if (array_key_exists('parent', $entry_data)) {
94 $this->setParent((string) $entry_data['parent']);
95 }
96 if (array_key_exists('children', $entry_data)) {
97 $this->setChildren($entry_data['children']);
98 }
99 if (array_key_exists('examples_path', $entry_data)) {
100 $this->examples_path = $entry_data['examples_path'];
101 }
102 if (array_key_exists('examples_namespace', $entry_data)) {
103 $this->examples_namespace = $entry_data['examples_namespace'];
104 }
105 if (array_key_exists('examples', $entry_data)) {
106 $this->examples = $entry_data['examples'];
107 } else {
108 $this->readExamples();
109 }
110 }
111
112 public function getId(): string
113 {
114 return $this->id;
115 }
116
117 public function setId(string $id): void
118 {
119 $this->assert()->isString($id, false);
120 $this->id = $id;
121 }
122
123 public function getTitle(): string
124 {
125 return $this->title;
126 }
127
128 public function setTitle(string $title): void
129 {
130 $this->assert()->isString($title, false);
131 $this->title = $title;
132 }
133
134 public function isAbstract(): bool
135 {
136 return $this->is_abstract;
137 }
138
139 public function setIsAbstract(bool $is_abstract): void
140 {
141 $this->is_abstract = $is_abstract;
142 }
143
144 public function getStatusEntry(): string
145 {
146 return $this->status_entry;
147 }
148
149 public function setStatusEntry(string $status_entry): void
150 {
151 $this->assert()->isString($status_entry);
152 $this->status_entry = $status_entry;
153 }
154
155 public function getStatusImplementation(): string
156 {
158 }
159
161 {
162 $this->assert()->isString($status_implementation);
163
164 $this->status_implementation = $status_implementation;
165 }
166
168 {
169 return $this->description;
170 }
171
172 public function getDescriptionAsArray(): array
173 {
174 return $this->description->getDescription();
175 }
176
181 {
182 $this->assert()->isTypeOf($description, ComponentEntryDescription::class);
183 $this->description = $description;
184 }
185
186 public function getBackground(): string
187 {
188 return $this->background;
189 }
190
191 public function setBackground(string $background): void
192 {
193 $this->assert()->isString($background);
194 $this->background = $background;
195 }
196
197 public function getContext(): array
198 {
199 return $this->context;
200 }
201
202 public function setContext(array $context): void
203 {
204 $this->assert()->isArray($context);
205 $this->context = $context;
206 }
207
208 public function getFeatureWikiReferences(): array
209 {
211 }
212
214 {
215 $this->assert()->isArray($feature_wiki_references);
216 $this->feature_wiki_references = $feature_wiki_references;
217 }
218
219 public function getRules(): ?ComponentEntryRules
220 {
221 return $this->rules;
222 }
223
224 public function getRulesAsArray(): array
225 {
226 if ($this->rules) {
227 return $this->rules->getRules();
228 } else {
229 return [];
230 }
231 }
232
233 public function setRules(ComponentEntryRules $rules): void
234 {
235 $this->assert()->isTypeOf($rules, ComponentEntryRules::class);
236 $this->rules = $rules;
237 }
238
239 public function getSelector(): string
240 {
241 return $this->selector;
242 }
243
244 public function setSelector(string $selector): void
245 {
246 $this->assert()->isString($selector);
247 $this->selector = $selector;
248 }
249
250 public function setLessVariables(array $less_variables): void
251 {
252 $this->assert()->isArray($less_variables);
253 $this->less_variables = $less_variables;
254 }
255
256 public function getLessVariables(): array
257 {
259 }
260
261 public function getPath(): string
262 {
263 return $this->path;
264 }
265
266 public function setPath(string $path): void
267 {
268 $this->assert()->isString($path);
269 $this->path = $path;
270 }
271
272 public function getParent(): ?string
273 {
274 return $this->parent;
275 }
276
277 public function setParent(string $parent): void
278 {
279 $this->parent = $parent;
280 }
281
285 public function getChildren(): array
286 {
287 return $this->children;
288 }
289
293 public function setChildren(array $children): void
294 {
295 $this->children = $children;
296 }
297
298 public function addChild(string $child): void
299 {
300 $this->children[] = $child;
301 }
302
306 public function addChildren(array $children): void
307 {
308 $this->setChildren(array_merge($this->children, $children));
309 }
310
311 public function getExamples(): array
312 {
313 return $this->examples;
314 }
315
316 protected function readExamples(): void
317 {
318 $this->examples = array();
319 $case_insensitive_path = $this->getCaseInsensitiveExampleFolder();
320 if (is_dir($case_insensitive_path)) {
321 foreach (scandir($case_insensitive_path) as $file_name) {
322 $example_path = $this->getExamplesPath() . "/" . $file_name;
323 if (is_file($example_path) && pathinfo($example_path)["extension"] == "php") {
324 $example_name = str_replace(".php", "", $file_name);
325 $this->examples[$example_name] = $this->trimRootDirectory($example_path);
326 }
327 }
328 }
329 }
330
336 protected function getCaseInsensitiveExampleFolder(): string
337 {
338 $parent_folder = $this->ilias_root . '/' . dirname($this->getExamplesPath());
339
340 if (is_dir($parent_folder)) {
341 foreach (scandir($parent_folder) as $folder_name) {
342 if (strtolower($folder_name) == strtolower(basename($this->getExamplesPath()))) {
343 return $parent_folder . "/" . $folder_name;
344 }
345 }
346 }
347
348 return "";
349 }
350
351 public function getExamplesPath(): string
352 {
353 if (!$this->examples_path) {
354 $path_components = str_replace(
355 "/Factory",
356 "",
357 str_replace("Component", "examples", $this->getPath())
358 )
359 . "/" . str_replace(" ", "", $this->getTitle());
360 $path_array = self::array_iunique(explode("/", $path_components));
361 if ($path_array[4] !== "examples") {
362 array_splice($path_array, 4, 0, 'examples');
363 }
364 $this->examples_path = implode("/", $path_array);
365 }
367 }
368
369 public function getExamplesNamespace(): string
370 {
371 if (!$this->examples_namespace) {
372 $path = str_replace("src/", "", $this->getExamplesPath());
373 $this->examples_namespace = str_replace(
374 "/",
375 "\\",
376 str_replace("components/", "", $path)
377 );
378 }
380 }
381
382 public function getNamespace(): string
383 {
384 return $this->namesapce;
385 }
386
387 public function setNamespace(string $namespace): void
388 {
389 $this->namesapce = $namespace;
390 }
391
392 private static function array_iunique(array $array): array
393 {
394 return array_intersect_key(
395 $array,
396 array_unique(array_map("StrToLower", $array))
397 );
398 }
399
400 public function jsonSerialize(): array
401 {
402 $description = $this->getDescription();
403 if ($description) {
404 $description_serialized = $description->jsonSerialize();
405 } else {
406 $description_serialized = "";
407 }
408
409 $rules = $this->getRules();
410 if ($rules) {
411 $rules_serialized = $rules->jsonSerialize();
412 } else {
413 $rules_serialized = "";
414 }
415
416 return array(
417 'id' => $this->getId(),
418 'title' => $this->getTitle(),
419 'abstract' => $this->isAbstract(),
420 'status_entry' => $this->getStatusEntry(),
421 'status_implementation' => $this->getStatusImplementation(),
422 'description' => $description_serialized,
423 'background' => $this->getBackground(),
424 'context' => $this->getContext(),
425 'selector' => $this->getSelector(),
426 'feature_wiki_references' => $this->getFeatureWikiReferences(),
427 'rules' => $rules_serialized,
428 'parent' => $this->getParent(),
429 'children' => $this->getChildren(),
430 'less_variables' => $this->getLessVariables(),
431 'path' => $this->getPath(),
432 'namespace' => $this->getNamespace(),
433 'examples_path' => $this->getExamplesPath(),
434 'examples_namespace' => $this->getExamplesNamespace(),
435 'examples' => $this->getExamples(),
436 );
437 }
438
439 protected function trimRootDirectory(string $path): string
440 {
441 return str_replace($this->ilias_root . '/', '', $path);
442 }
443
444 protected function prependRootDirectory(string $path): string
445 {
446 return "$this->ilias_root/$path";
447 }
448}
Abstract Entry Part to share some common entry functionality.
Stores Information of UI Components parsed from YAML, examples and less files.
setFeatureWikiReferences(array $feature_wiki_references)
setStatusImplementation(string $status_implementation)
setDescription(ComponentEntryDescription $description)
getCaseInsensitiveExampleFolder()
Note case handling of is dir is different from OS to OS, therefore while reading the examples from th...
if($err=$client->getError()) $namespace
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc