ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\KeyValueStorage\Internal\Values Class Reference

Translates between the values a consumer works with and the strings a repository stores. More...

+ Collaboration diagram for ILIAS\KeyValueStorage\Internal\Values:

Public Member Functions

 __construct (Refinery $refinery)
 
 encode (mixed $value)
 
 decode (string $value)
 

Private Member Functions

 checkEncodable (mixed $value)
 

Private Attributes

Transformation $encode
 
Transformation $decode
 

Detailed Description

Translates between the values a consumer works with and the strings a repository stores.

Values are stored as JSON via Refinery encode/decode transformations. serialize()/unserialize() are never used, so reading a value can never instantiate an object.

Definition at line 37 of file Values.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\KeyValueStorage\Internal\Values::__construct ( Refinery  $refinery)

Definition at line 43 of file Values.php.

44 {
45 $this->encode = $refinery->encode()->json();
46 $this->decode = $refinery->decode()->json();
47 }

References ILIAS\KeyValueStorage\Internal\Values\decode(), and ILIAS\KeyValueStorage\Internal\Values\encode().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkEncodable()

ILIAS\KeyValueStorage\Internal\Values::checkEncodable ( mixed  $value)
private

Definition at line 79 of file Values.php.

79 : void
80 {
81 if ($value === null || \is_scalar($value)) {
82 return;
83 }
84
85 if (\is_array($value)) {
86 foreach ($value as $item) {
87 $this->checkEncodable($item);
88 }
89
90 return;
91 }
92
93 if ($value instanceof \JsonSerializable) {
94 $this->checkEncodable($value->jsonSerialize());
95
96 return;
97 }
98
99 throw new \InvalidArgumentException(
100 'Only null, scalars, arrays of those and objects implementing JsonSerializable can be stored, got '
101 . \get_debug_type($value) . '.'
102 );
103 }

References ILIAS\KeyValueStorage\Internal\Values\checkEncodable().

Referenced by ILIAS\KeyValueStorage\Internal\Values\checkEncodable(), and ILIAS\KeyValueStorage\Internal\Values\encode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode()

ILIAS\KeyValueStorage\Internal\Values::decode ( string  $value)
Exceptions
InvalidStoredValueExceptionif the stored string cannot be read back

Definition at line 70 of file Values.php.

70 : mixed
71 {
72 try {
73 return $this->decode->transform($value);
74 } catch (\InvalidArgumentException $e) {
75 throw new InvalidStoredValueException('The stored value is not valid JSON.', 0, $e);
76 }
77 }

References Vendor\Package\$e, and ILIAS\KeyValueStorage\Internal\Values\decode().

Referenced by ILIAS\KeyValueStorage\Internal\Values\__construct(), and ILIAS\KeyValueStorage\Internal\Values\decode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode()

ILIAS\KeyValueStorage\Internal\Values::encode ( mixed  $value)
Exceptions

InvalidArgumentException if the value cannot be stored

Definition at line 52 of file Values.php.

52 : string
53 {
54 $this->checkEncodable($value);
55
56 try {
57 return $this->encode->transform($value);
58 } catch (\JsonException $e) {
59 throw new \InvalidArgumentException(
60 'The value could not be encoded: ' . $e->getMessage(),
61 0,
62 $e
63 );
64 }
65 }

References Vendor\Package\$e, ILIAS\KeyValueStorage\Internal\Values\checkEncodable(), and ILIAS\KeyValueStorage\Internal\Values\encode().

Referenced by ILIAS\KeyValueStorage\Internal\Values\__construct(), and ILIAS\KeyValueStorage\Internal\Values\encode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $decode

Transformation ILIAS\KeyValueStorage\Internal\Values::$decode
private

Definition at line 41 of file Values.php.

◆ $encode

Transformation ILIAS\KeyValueStorage\Internal\Values::$encode
private

Definition at line 39 of file Values.php.


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