ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
DList.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Data\Description;
22 
23 use ILIAS\Data\Text;
24 
25 class 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)
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, lists, maps and objects and helpful (hopefully...) human readable texts.
Definition: Description.php:32
__construct(Container $dic, ilPlugin $plugin)