File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 2525 "php" : " ^8.3" ,
2626 "ext-grpc" : " *" ,
2727 "google/protobuf" : " ^4.28" ,
28- "grpc/grpc" : " ^1.57"
28+ "grpc/grpc" : " ^1.57" ,
29+ "symfony/serializer" : " ^7.3" ,
30+ "symfony/property-access" : " ^7.3"
2931 },
3032 "require-dev" : {
3133 "laravel/pint" : " ^1.18" ,
Original file line number Diff line number Diff line change 1212use SpaceX \API \Device \Response ;
1313use SRWieZ \StarlinkClient \Exceptions \GrpcCallFailedException ;
1414use SRWieZ \StarlinkClient \Exceptions \PermissionDeniedException ;
15+ use Symfony \Component \Serializer \Encoder \JsonEncoder ;
16+ use Symfony \Component \Serializer \Normalizer \ObjectNormalizer ;
17+ use Symfony \Component \Serializer \Serializer ;
1518
1619class GrpcClient
1720{
@@ -81,16 +84,18 @@ public static function responseToArray(?Message $response): array
8184 return [];
8285 }
8386
84- $ return = ( array ) json_decode (
85- json: $ response -> serializeToJsonString () ,
86- associative: true ,
87+ $ serializer = new Serializer (
88+ normalizers: [ new ObjectNormalizer ] ,
89+ encoders: [ new JsonEncoder ]
8790 );
8891
89- if (json_last_error () !== JSON_ERROR_NONE ) {
90- throw new \RuntimeException ('Failed to decode JSON response: ' .json_last_error_msg ());
91- }
92-
93- return $ return ;
92+ return $ serializer ->normalize (
93+ data: $ response ,
94+ format: 'json ' ,
95+ context: [
96+ 'json_encode_options ' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT ,
97+ ]
98+ );
9499 }
95100
96101 public function disconnect (): void
You can’t perform that action at this time.
0 commit comments