@@ -58,7 +58,8 @@ |
||
58 | 58 | 'json' => new JsonSerializer(), |
59 | 59 | 'serializer' => new PhpSerializer(), |
60 | 60 | ]; |
61 | - if (\class_exists(Message::class)) { |
|
61 | + if (\class_exists(Message::class)) |
|
62 | + { |
|
62 | 63 | $serializers['proto'] = new ProtoSerializer(); |
63 | 64 | } |
64 | 65 |
@@ -27,7 +27,8 @@ |
||
27 | 27 | * @type string $url |
28 | 28 | * } |
29 | 29 | */ |
30 | - public function __construct($data = NULL) { |
|
30 | + public function __construct($data = NULL) |
|
31 | + { |
|
31 | 32 | \Spiral\Tests\Serializer\Fixture\GPBMetadata\Service::initOnce(); |
32 | 33 | parent::__construct($data); |
33 | 34 | } |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | { |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - if (!\class_exists(Message::class)) { |
|
17 | + if (!\class_exists(Message::class)) |
|
18 | + { |
|
18 | 19 | throw new SerializerException('Package `google/protobuf` is not installed.'); |
19 | 20 | } |
20 | 21 | } |
@@ -24,7 +25,8 @@ discard block |
||
24 | 25 | */ |
25 | 26 | public function serialize(mixed $payload): string|\Stringable |
26 | 27 | { |
27 | - if (!$payload instanceof Message) { |
|
28 | + if (!$payload instanceof Message) |
|
29 | + { |
|
28 | 30 | throw new InvalidArgumentException(\sprintf( |
29 | 31 | 'Payload must be of type `%s`, received `%s`.', |
30 | 32 | Message::class, |
@@ -41,11 +43,13 @@ discard block |
||
41 | 43 | */ |
42 | 44 | public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
43 | 45 | { |
44 | - if (\is_object($type)) { |
|
46 | + if (\is_object($type)) |
|
47 | + { |
|
45 | 48 | $type = $type::class; |
46 | 49 | } |
47 | 50 | |
48 | - if ($type === null || !\class_exists($type) || !\is_a($type, Message::class, true)) { |
|
51 | + if ($type === null || !\class_exists($type) || !\is_a($type, Message::class, true)) |
|
52 | + { |
|
49 | 53 | throw new InvalidArgumentException(\sprintf( |
50 | 54 | 'Parameter `$type` must be of type: `%s`, received `%s`.', |
51 | 55 | Message::class, |
@@ -55,9 +59,12 @@ discard block |
||
55 | 59 | |
56 | 60 | $object = new $type(); |
57 | 61 | |
58 | - try { |
|
62 | + try |
|
63 | + { |
|
59 | 64 | $object->mergeFromString((string) $payload); |
60 | - } catch (\Throwable $e) { |
|
65 | + } |
|
66 | + catch (\Throwable $e) |
|
67 | + { |
|
61 | 68 | throw new UnserializeException( |
62 | 69 | \sprintf('Failed to unserialize data: %s', $e->getMessage()), |
63 | 70 | $e->getCode(), |