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

Public Member Functions

 __construct (Text\SimpleDocumentMarkdown $description, protected ValueType $type,)
 
 getType ()
 
 getPrimitiveRepresentation (mixed $data)
 Each of the types that can be described has a canonical representation created from primitive PHP types. More...
 
- 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 DValue.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Data\Description\DValue::__construct ( Text\SimpleDocumentMarkdown  $description,
protected ValueType  $type 
)

Definition at line 27 of file DValue.php.

30 {
31 parent::__construct($description);
32 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ getPrimitiveRepresentation()

ILIAS\Data\Description\DValue::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 39 of file DValue.php.

39 : mixed
40 {
41 switch ($this->type) {
42 case ValueType::INT:
43 if (!is_int($data)) {
44 return fn() => yield "Expected an integer.";
45 }
46 return $data;
47
48 case ValueType::FLOAT:
49 if (!is_float($data)) {
50 return fn() => yield "Expected a float.";
51 }
52 return $data;
53
54 case ValueType::STRING:
55 if (!is_string($data)) {
56 return fn() => yield "Expected a string.";
57 }
58 return $data;
59
60 case ValueType::DATETIME:
61 if (!$data instanceof \DateTimeImmutable) {
62 return fn() => yield "Expected a \\DateTimeImmutable.";
63 }
64 return $data;
65
66 case ValueType::BOOL:
67 if (!is_bool($data)) {
68 return fn() => yield "Expected a bool.";
69 }
70 return $data;
71
72 case ValueType::NULL:
73 if (!is_null($data)) {
74 return fn() => yield "Expected null.";
75 }
76 return $data;
77
78 default:
79 throw new \LogicException("Unmatch type.");
80 }
81 }

References $data, and ILIAS\Data\Description\NULL.

◆ getType()

ILIAS\Data\Description\DValue::getType ( )

Definition at line 34 of file DValue.php.

34 : ValueType
35 {
36 return $this->type;
37 }

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