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