ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
TypeData.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26#[\AllowDynamicProperties]
27class TypeData extends \ArrayObject
28{
29 public function serialize(): string
30 {
31 return $this->__serialize()['data'];
32 }
33
34 public function unserialize(string $data): void
35 {
36 $this->__unserialize(['data' => $data]);
37 }
38
42 public function __serialize(): array
43 {
44 return ['data' => json_encode($this, JSON_THROW_ON_ERROR)];
45 }
46
50 public function __unserialize(array $data): void
51 {
52 foreach ((array) (json_decode($data['data'] ?? '[]', true)) as $k => $item) {
53 $this->$k = $item;
54 $this[$k] = $item;
55 }
56 }
57
58 public function with(string $key, mixed $value): static
59 {
60 $clone = clone $this;
61 $clone->$key = $value;
62 $clone[$key] = $value;
63 return $clone;
64 }
65
66}