ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Data\Description\DMap Class Reference
+ Inheritance diagram for ILIAS\Data\Description\DMap:
+ Collaboration diagram for ILIAS\Data\Description\DMap:

Public Member Functions

 __construct (Text\SimpleDocumentMarkdown $description, protected DValue $key_type, protected Description $value_type)
 
 getPrimitiveRepresentation (mixed $data)
 Each of the types that can be described has a canonical representation created from primitive PHP types. More...
 
 getKeyType ()
 
 getValueType ()
 
- Public Member Functions inherited from ILIAS\Data\Description\Description
 __construct (protected ?Text\SimpleDocumentMarkdown $description,)
 
 getDescription ()
 
 getPrimitiveRepresentation (mixed $data)
 Each of the types that can be described has a canonical representation created from primitive PHP types. More...
 
 matches (mixed $data)
 

Detailed Description

Definition at line 25 of file DMap.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Data\Description\DMap::__construct ( Text\SimpleDocumentMarkdown  $description,
protected DValue  $key_type,
protected Description  $value_type 
)

Definition at line 29 of file DMap.php.

33 {
34 parent::__construct($description);
35 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ getKeyType()

ILIAS\Data\Description\DMap::getKeyType ( )

Definition at line 72 of file DMap.php.

72 : DValue
73 {
74 return $this->key_type;
75 }

◆ getPrimitiveRepresentation()

ILIAS\Data\Description\DMap::getPrimitiveRepresentation ( mixed  $data)

Each of the types that can be described has a canonical representation created from primitive PHP types.

This attempts to transform the provided data into such a representation.

If this returns a \Closure, the data cannot be transformed into such a representation and the \Closure will produce a generator that provides a list of defects where $data does not match the description. If this does return something else it will be plain old php data according to the description.

Reimplemented from ILIAS\Data\Description\Description.

Definition at line 37 of file DMap.php.

37 : mixed
38 {
39 if (!is_array($data)) {
40 return fn() => yield "Expected an array.";
41 }
42
43 $repr = [];
44 $errors = [];
45
46 foreach ($data as $k => $v) {
47 $key = $this->key_type->getPrimitiveRepresentation($k);
48 $value = $this->value_type->getPrimitiveRepresentation($v);
49
50 $key_is_error = $key instanceof \Closure;
51 $value_is_error = $value instanceof \Closure;
52
53 if ($key_is_error) {
54 $errors[] = $key;
55 }
56 if ($value_is_error) {
57 $errors[] = $value;
58 }
59
60 if (!$key_is_error && !$value_is_error) {
61 $repr[$key] = $value;
62 }
63 }
64
65 if ($errors) {
66 return $this->mergeErrors($errors);
67 }
68
69 return $repr;
70 }

References $data.

◆ getValueType()

ILIAS\Data\Description\DMap::getValueType ( )

Definition at line 77 of file DMap.php.

78 {
79 return $this->value_type;
80 }
This describes some datastructure in terms of standard data structures such as primitives,...
Definition: Description.php:33

The documentation for this class was generated from the following file: