Skip to content

Commit

Permalink
Fix the handling of required fields populated from headers
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Jun 11, 2024
1 parent 8f779a4 commit ef78e53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,39 +190,36 @@ private function generatePopulator(Operation $operation, StructureShape $shape,
$memberShape = $member->getShape();
switch ($memberShape->getType()) {
case 'timestamp':
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? new \DateTimeImmutable($headers["LOCATION_NAME"][0]) : null;' . "\n", [
'PROPERTY_NAME' => $propertyName,
'LOCATION_NAME' => $locationName,
]);
$input = 'new \DateTimeImmutable($headers["LOCATION_NAME"][0])';

break;
case 'integer':
case 'long':
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? (int) $headers["LOCATION_NAME"][0] : null;' . "\n", [
'PROPERTY_NAME' => $propertyName,
'LOCATION_NAME' => $locationName,
]);
$input = '(int) $headers["LOCATION_NAME"][0]';

break;
case 'boolean':
$this->requirementsRegistry->addRequirement('ext-filter');

$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) : null;' . "\n", [
'PROPERTY_NAME' => $propertyName,
'LOCATION_NAME' => $locationName,
]);
$input = 'filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN)';

break;
case 'string':
$body .= strtr('$this->PROPERTY_NAME = $headers["LOCATION_NAME"][0] ?? null;' . "\n", [
'PROPERTY_NAME' => $propertyName,
'LOCATION_NAME' => $locationName,
]);
$input = '$headers["LOCATION_NAME"][0]';

break;
default:
throw new \RuntimeException(sprintf('Type %s is not yet implemented', $memberShape->getType()));
}

if (!$member->isRequired()) {
$input = 'isset($headers["LOCATION_NAME"][0]) ? ' . $input . ' : null';
}

$body .= strtr('$this->PROPERTY_NAME = ' . $input . ";\n", [
'PROPERTY_NAME' => $propertyName,
'LOCATION_NAME' => $locationName,
]);
}

// This will catch arbitrary values that exists in undefined "headers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function populateResult(Response $response): void
{
$headers = $response->getHeaders();

$this->location = $headers['location'][0] ?? null;
$this->location = $headers['location'][0];

$data = new \SimpleXMLElement($response->getContent());
$this->hostedZone = new HostedZone([
Expand Down

0 comments on commit ef78e53

Please sign in to comment.