|
19 | 19 |
|
20 | 20 | use Google\ApiCore\ArrayTrait; |
21 | 21 | use Google\ApiCore\Options\CallOptions; |
22 | | -use Google\Protobuf\NullValue; |
23 | 22 | use Google\Protobuf\Internal\Message; |
| 23 | +use Google\Protobuf\NullValue; |
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * @internal |
@@ -272,25 +272,28 @@ private function splitOptionalArgs(array $input, array $extraAllowedKeys = []): |
272 | 272 | * the CallOptions classname. Parameters are split and returned in the order |
273 | 273 | * that the options types are provided. |
274 | 274 | */ |
275 | | - private function validateOptions(array $options, array|string ...$optionTypes): array |
| 275 | + private function validateOptions(array $options, array|Message|string ...$optionTypes): array |
276 | 276 | { |
277 | 277 | $splitOptions = []; |
278 | 278 | foreach ($optionTypes as $optionType) { |
279 | 279 | if (is_array($optionType)) { |
280 | 280 | $splitOptions[] = $this->pluckArray($optionType, $options); |
281 | | - } elseif (is_string($optionType)) { |
282 | | - if (is_subclass_of($optionType, Message::class)) { |
| 281 | + } else { |
| 282 | + if ($optionType === CallOptions::class) { |
| 283 | + $callOptionKeys = array_keys((new CallOptions([]))->toArray()); |
| 284 | + $splitOptions[] = $this->pluckArray($callOptionKeys, $options); |
| 285 | + } else { |
283 | 286 | $messageKeys = array_map( |
284 | 287 | fn ($method) => lcfirst(substr($method, 3)), |
285 | 288 | array_filter( |
286 | 289 | get_class_methods($optionType), |
287 | 290 | fn ($m) => 0 === strpos($m, 'get') |
288 | 291 | ) |
289 | 292 | ); |
290 | | - $splitOptions[] = $this->pluckArray($messageKeys, $options); |
291 | | - } elseif ($optionType === CallOptions::class) { |
292 | | - $callOptionKeys = array_keys((new CallOptions([]))->toArray()); |
293 | | - $splitOptions[] = $this->pluckArray($callOptionKeys, $options); |
| 293 | + $messageOptions = $this->pluckArray($messageKeys, $options); |
| 294 | + $splitOptions[] = $optionType instanceof Message |
| 295 | + ? $this->serializer->decodeMessage($optionType, $messageOptions) |
| 296 | + : $messageOptions; |
294 | 297 | } |
295 | 298 | } |
296 | 299 | } |
|
0 commit comments