ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DList.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
25class DList extends Description
26{
27 use ErrorHandling;
28
29 public function __construct(
30 Text\SimpleDocumentMarkdown $description,
31 protected Description $value_type
32 ) {
33 parent::__construct($description);
34 }
35
36 public function getPrimitiveRepresentation(mixed $data): mixed
37 {
38 if (!is_array($data)) {
39 return fn() => yield "Expected an array.";
40 }
41
42 $repr = [];
43 $errors = [];
44
45 foreach ($data as $v) {
46 $value = $this->value_type->getPrimitiveRepresentation($v);
47
48 if ($value instanceof \Closure) {
49 $errors[] = $value;
50 } else {
51 $repr[] = $value;
52 }
53 }
54
55 if ($errors) {
56 return $this->mergeErrors($errors);
57 }
58
59 return $repr;
60 }
61
62 public function getValueType(): Description
63 {
64 return $this->value_type;
65 }
66}
getPrimitiveRepresentation(mixed $data)
Each of the types that can be described has a canonical representation created from primitive PHP typ...
Definition: DList.php:36
__construct(Text\SimpleDocumentMarkdown $description, protected Description $value_type)
Definition: DList.php:29
This describes some datastructure in terms of standard data structures such as primitives,...
Definition: Description.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc