|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Part of SplTypes package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Adrien Loyant <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Ducks\Component\SplTypes; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* SplEnumBackedTrait expose magic method in order to use an SplEnum class which implements SplBackedEnum. |
|
18
|
|
|
* |
|
19
|
|
|
* @template T |
|
20
|
|
|
* |
|
21
|
|
|
* @phpstan-require-extends SplEnum |
|
22
|
|
|
* @phpstan-require-implements SplBackedEnum |
|
23
|
|
|
* |
|
24
|
|
|
* @psalm-api |
|
25
|
|
|
*/ |
|
26
|
|
|
trait SplEnumBackedTrait |
|
27
|
|
|
{ |
|
28
|
|
|
use SplEnumUnitTrait { |
|
29
|
|
|
SplEnumUnitTrait::__serialize as __unitSerialize; |
|
30
|
|
|
SplEnumUnitTrait::__unserialize as __unitUnserialize; |
|
31
|
|
|
SplEnumUnitTrait::__set_state as __unitSetState; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Serialize object. |
|
36
|
|
|
* |
|
37
|
|
|
* @return array<string,mixed> |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __serialize(): array |
|
40
|
|
|
{ |
|
41
|
|
|
$result = $this->__unitSerialize(); |
|
42
|
|
|
|
|
43
|
|
|
return $result; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Unserialize object. |
|
48
|
|
|
* |
|
49
|
|
|
* @param array<string,mixed> $data |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __unserialize(array $data): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->__unitUnserialize($data); |
|
56
|
|
|
|
|
57
|
|
|
$this->value = &$this->__default; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Instanciate an exported object. |
|
62
|
|
|
* |
|
63
|
|
|
* @param array<string,mixed> $properties |
|
64
|
|
|
* |
|
65
|
|
|
* @return static |
|
66
|
|
|
* |
|
67
|
|
|
* @psalm-suppress UnsafeInstantiation |
|
68
|
|
|
*/ |
|
69
|
|
|
#[\ReturnTypeWillChange] |
|
70
|
|
|
public static function __set_state(array $properties): SplBackedEnum |
|
71
|
|
|
{ |
|
72
|
|
|
/** @var static $object */ |
|
73
|
|
|
$object = static::__unitSetState($properties); |
|
74
|
|
|
$object->value = $properties['value']; |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
return $object; |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Dumping object. |
|
81
|
|
|
* |
|
82
|
|
|
* @return array<string,string> |
|
83
|
|
|
* |
|
84
|
|
|
* @codeCoverageIgnore |
|
85
|
|
|
*/ |
|
86
|
|
|
public function __debugInfo(): array |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
'name' => $this->name, |
|
90
|
|
|
'value' => $this->value, |
|
91
|
|
|
]; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|