Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
83.33% |
5 / 6 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
BuiltinSerializer | |
83.33% |
5 / 6 |
|
50.00% |
1 / 2 |
4.07 | |
0.00% |
0 / 1 |
saveImpl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
loadImpl | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\Core\Serialization; |
6 | |
7 | use JsonException; |
8 | use Exception; |
9 | use PeServer\Core\Binary; |
10 | use PeServer\Core\Serialization\SerializerBase; |
11 | use PeServer\Core\Throws\JsonDecodeException; |
12 | use PeServer\Core\Throws\JsonEncodeException; |
13 | use PeServer\Core\Throws\ParseException; |
14 | use PeServer\Core\Throws\Throws; |
15 | use PeServer\Core\TypeUtility; |
16 | |
17 | /** |
18 | * PHP組み込みシリアライザー。 |
19 | */ |
20 | final class BuiltinSerializer extends SerializerBase |
21 | { |
22 | #region SerializerBase |
23 | |
24 | protected function saveImpl(array|object $value): Binary |
25 | { |
26 | $data = serialize($value); |
27 | return new Binary($data); |
28 | } |
29 | |
30 | protected function loadImpl(Binary $value): array|object |
31 | { |
32 | $data = unserialize($value->raw); |
33 | if (is_array($data) || is_object($data)) { |
34 | return $data; |
35 | } |
36 | |
37 | throw new Exception(TypeUtility::getType($data)); |
38 | } |
39 | |
40 | #endregion |
41 | } |