|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace AsyncAws\CodeGenerator\Generator\RequestSerializer; |
| 6 | + |
| 7 | +use AsyncAws\CodeGenerator\Definition\ListShape; |
| 8 | +use AsyncAws\CodeGenerator\Definition\MapShape; |
| 9 | +use AsyncAws\CodeGenerator\Definition\Member; |
| 10 | +use AsyncAws\CodeGenerator\Definition\StructureMember; |
| 11 | + |
| 12 | +/** |
| 13 | + * EC2 wire-format variant of the query protocol. |
| 14 | + * |
| 15 | + * Differences vs standard query: |
| 16 | + * - Lists are encoded as `Parent.$index` — no `.member` infix, the list-member |
| 17 | + * locationName is ignored, and the flattened/non-flattened distinction is |
| 18 | + * irrelevant (every list serializes positionally). |
| 19 | + * - Structure-member names prefer `queryName` verbatim, else `ucfirst(locationName)`, |
| 20 | + * else the PHP key (already PascalCase in AWS EC2 models). |
| 21 | + * |
| 22 | + * Mirrors aws-sdk-php's `Aws\Api\Serializer\Ec2ParamBuilder`. |
| 23 | + * |
| 24 | + * @internal |
| 25 | + */ |
| 26 | +class Ec2QuerySerializer extends QuerySerializer |
| 27 | +{ |
| 28 | + protected function getQueryName(Member $member, string $default): string |
| 29 | + { |
| 30 | + if (null !== $member->getQueryName()) { |
| 31 | + return $member->getQueryName(); |
| 32 | + } |
| 33 | + if (null !== $locationName = $member->getLocationName()) { |
| 34 | + return ucfirst($locationName); |
| 35 | + } |
| 36 | + |
| 37 | + return $default; |
| 38 | + } |
| 39 | + |
| 40 | + protected function getName(Member $member): string |
| 41 | + { |
| 42 | + if (!$member instanceof StructureMember) { |
| 43 | + throw new \RuntimeException('Guessing the name for this member is not yet implemented'); |
| 44 | + } |
| 45 | + |
| 46 | + $name = $this->getQueryName($member, $member->getName()); |
| 47 | + $shape = $member->getShape(); |
| 48 | + |
| 49 | + if ($shape instanceof ListShape) { |
| 50 | + return $name; |
| 51 | + } |
| 52 | + |
| 53 | + if ($shape instanceof MapShape) { |
| 54 | + return $name . ($shape->isFlattened() ? '' : '.entry'); |
| 55 | + } |
| 56 | + |
| 57 | + return $name; |
| 58 | + } |
| 59 | +} |
0 commit comments