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
|
|
|
* SplEnumUnitTrait expose magic method in order to use an SplEnum class which implements SplUnitEnum. |
18
|
|
|
* |
19
|
|
|
* @phpstan-require-extends SplEnum |
20
|
|
|
* @phpstan-require-implements SplUnitEnum |
21
|
|
|
* |
22
|
|
|
* @psalm-api |
23
|
|
|
*/ |
24
|
|
|
trait SplEnumUnitTrait |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Serialize object. |
28
|
|
|
* |
29
|
|
|
* @return array<string,mixed> |
30
|
|
|
*/ |
31
|
|
|
public function __serialize(): array |
32
|
|
|
{ |
33
|
|
|
$result = parent::__serialize(); |
34
|
|
|
$result['name'] = $this->name; |
35
|
|
|
|
36
|
|
|
return $result; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Unserialize object. |
41
|
|
|
* |
42
|
|
|
* @param array<string,mixed> $data |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function __unserialize(array $data): void |
47
|
|
|
{ |
48
|
|
|
parent::__unserialize($data); |
49
|
|
|
|
50
|
|
|
$this->name = $data['name']; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Instanciate an exported object. |
55
|
|
|
* |
56
|
|
|
* @param array<string,mixed> $properties |
57
|
|
|
* |
58
|
|
|
* @return static |
59
|
|
|
* |
60
|
|
|
* @psalm-suppress UnsafeInstantiation |
61
|
|
|
*/ |
62
|
|
|
public static function __set_state(array $properties): SplUnitEnum |
63
|
|
|
{ |
64
|
|
|
/** @var static $object */ |
65
|
|
|
// @phpstan-ignore-next-line |
66
|
|
|
$object = /** @scrutinizer ignore-call */ new static(); |
67
|
|
|
$object->name = $properties['name']; |
|
|
|
|
68
|
|
|
|
69
|
|
|
return $object; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Dumping object. |
74
|
|
|
* |
75
|
|
|
* @return array<string,string> |
76
|
|
|
* |
77
|
|
|
* @codeCoverageIgnore |
78
|
|
|
*/ |
79
|
|
|
public function __debugInfo(): array |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
'name' => $this->name, |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|