diff --git a/CHANGELOG.md b/CHANGELOG.md index 02b0727..fa5453a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Changed +- AWS enhancement: Documentation updates. - Add `Accept: application/json` header in request to fix incompatibility with 3rd party providers ## 1.0.2 diff --git a/composer.json b/composer.json index d524a73..31b9ac0 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.1-dev" } } } diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php index d4ddace..d69ec70 100644 --- a/src/Exception/ValidationException.php +++ b/src/Exception/ValidationException.php @@ -13,18 +13,18 @@ final class ValidationException extends ClientException { /** - * The field where the invalid entry was detected. + * A message with the reason for the validation exception error. * - * @var ValidationExceptionField[] + * @var ValidationExceptionReason::* */ - private $fieldList; + private $reason; /** - * A message with the reason for the validation exception error. + * The field where the invalid entry was detected. * - * @var ValidationExceptionReason::* + * @var ValidationExceptionField[] */ - private $reason; + private $fieldList; /** * @return ValidationExceptionField[] @@ -46,15 +46,15 @@ protected function populateResult(ResponseInterface $response): void { $data = $response->toArray(false); - $this->fieldList = $this->populateResultValidationExceptionFieldList($data['fieldList'] ?? []); $this->reason = (string) $data['reason']; + $this->fieldList = $this->populateResultValidationExceptionFieldList($data['fieldList'] ?? []); } private function populateResultValidationExceptionField(array $json): ValidationExceptionField { return new ValidationExceptionField([ - 'Message' => (string) $json['message'], 'Name' => (string) $json['name'], + 'Message' => (string) $json['message'], ]); } diff --git a/src/Input/CalculateRouteMatrixRequest.php b/src/Input/CalculateRouteMatrixRequest.php index 0c48031..9945daa 100644 --- a/src/Input/CalculateRouteMatrixRequest.php +++ b/src/Input/CalculateRouteMatrixRequest.php @@ -22,28 +22,6 @@ final class CalculateRouteMatrixRequest extends Input */ private $calculatorName; - /** - * Specifies route preferences when traveling by `Car`, such as avoiding routes that use ferries or tolls. - * - * Requirements: `TravelMode` must be specified as `Car`. - * - * @var CalculateRouteCarModeOptions|null - */ - private $carModeOptions; - - /** - * Sets the time of departure as the current time. Uses the current time to calculate the route matrix. You can't set - * both `DepartureTime` and `DepartNow`. If neither is set, the best time of day to travel with the best traffic - * conditions is used to calculate the route matrix. - * - * Default Value: `false` - * - * Valid Values: `false` | `true` - * - * @var bool|null - */ - private $departNow; - /** * The list of departure (origin) positions for the route matrix. An array of points, each of which is itself a 2-value * array defined in WGS 84 [^1] format: `[longitude, latitude]`. For example, `[-123.115, 49.285]`. @@ -67,21 +45,6 @@ final class CalculateRouteMatrixRequest extends Input */ private $departurePositions; - /** - * Specifies the desired time of departure. Uses the given time to calculate the route matrix. You can't set both - * `DepartureTime` and `DepartNow`. If neither is set, the best time of day to travel with the best traffic conditions - * is used to calculate the route matrix. - * - * > Setting a departure time in the past returns a `400 ValidationException` error. - * - * - In ISO 8601 [^1] format: `YYYY-MM-DDThh:mm:ss.sssZ`. For example, `2020–07-2T12:15:20.000Z+01:00` - * - * [^1]: https://www.iso.org/iso-8601-date-and-time-format.html - * - * @var \DateTimeImmutable|null - */ - private $departureTime; - /** * The list of destination positions for the route matrix. An array of points, each of which is itself a 2-value array * defined in WGS 84 [^1] format: `[longitude, latitude]`. For example, `[-122.339, 47.615]`. @@ -105,24 +68,6 @@ final class CalculateRouteMatrixRequest extends Input */ private $destinationPositions; - /** - * Set the unit system to specify the distance. - * - * Default Value: `Kilometers` - * - * @var DistanceUnit::*|null - */ - private $distanceUnit; - - /** - * The optional API key [^1] to authorize the request. - * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html - * - * @var string|null - */ - private $key; - /** * Specifies the mode of transport when calculating a route. Used in estimating the speed of travel and road * compatibility. @@ -147,6 +92,52 @@ final class CalculateRouteMatrixRequest extends Input */ private $travelMode; + /** + * Specifies the desired time of departure. Uses the given time to calculate the route matrix. You can't set both + * `DepartureTime` and `DepartNow`. If neither is set, the best time of day to travel with the best traffic conditions + * is used to calculate the route matrix. + * + * > Setting a departure time in the past returns a `400 ValidationException` error. + * + * - In ISO 8601 [^1] format: `YYYY-MM-DDThh:mm:ss.sssZ`. For example, `2020–07-2T12:15:20.000Z+01:00` + * + * [^1]: https://www.iso.org/iso-8601-date-and-time-format.html + * + * @var \DateTimeImmutable|null + */ + private $departureTime; + + /** + * Sets the time of departure as the current time. Uses the current time to calculate the route matrix. You can't set + * both `DepartureTime` and `DepartNow`. If neither is set, the best time of day to travel with the best traffic + * conditions is used to calculate the route matrix. + * + * Default Value: `false` + * + * Valid Values: `false` | `true` + * + * @var bool|null + */ + private $departNow; + + /** + * Set the unit system to specify the distance. + * + * Default Value: `Kilometers` + * + * @var DistanceUnit::*|null + */ + private $distanceUnit; + + /** + * Specifies route preferences when traveling by `Car`, such as avoiding routes that use ferries or tolls. + * + * Requirements: `TravelMode` must be specified as `Car`. + * + * @var CalculateRouteCarModeOptions|null + */ + private $carModeOptions; + /** * Specifies route preferences when traveling by `Truck`, such as avoiding routes that use ferries or tolls, and truck * specifications to consider when choosing an optimal road. @@ -157,48 +148,57 @@ final class CalculateRouteMatrixRequest extends Input */ private $truckModeOptions; + /** + * The optional API key [^1] to authorize the request. + * + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html + * + * @var string|null + */ + private $key; + /** * @param array{ * CalculatorName?: string, - * CarModeOptions?: null|CalculateRouteCarModeOptions|array, - * DepartNow?: null|bool, * DeparturePositions?: array[], - * DepartureTime?: null|\DateTimeImmutable|string, * DestinationPositions?: array[], - * DistanceUnit?: null|DistanceUnit::*, - * Key?: null|string, * TravelMode?: null|TravelMode::*, + * DepartureTime?: null|\DateTimeImmutable|string, + * DepartNow?: null|bool, + * DistanceUnit?: null|DistanceUnit::*, + * CarModeOptions?: null|CalculateRouteCarModeOptions|array, * TruckModeOptions?: null|CalculateRouteTruckModeOptions|array, + * Key?: null|string, * '@region'?: string|null, * } $input */ public function __construct(array $input = []) { $this->calculatorName = $input['CalculatorName'] ?? null; - $this->carModeOptions = isset($input['CarModeOptions']) ? CalculateRouteCarModeOptions::create($input['CarModeOptions']) : null; - $this->departNow = $input['DepartNow'] ?? null; $this->departurePositions = $input['DeparturePositions'] ?? null; - $this->departureTime = !isset($input['DepartureTime']) ? null : ($input['DepartureTime'] instanceof \DateTimeImmutable ? $input['DepartureTime'] : new \DateTimeImmutable($input['DepartureTime'])); $this->destinationPositions = $input['DestinationPositions'] ?? null; - $this->distanceUnit = $input['DistanceUnit'] ?? null; - $this->key = $input['Key'] ?? null; $this->travelMode = $input['TravelMode'] ?? null; + $this->departureTime = !isset($input['DepartureTime']) ? null : ($input['DepartureTime'] instanceof \DateTimeImmutable ? $input['DepartureTime'] : new \DateTimeImmutable($input['DepartureTime'])); + $this->departNow = $input['DepartNow'] ?? null; + $this->distanceUnit = $input['DistanceUnit'] ?? null; + $this->carModeOptions = isset($input['CarModeOptions']) ? CalculateRouteCarModeOptions::create($input['CarModeOptions']) : null; $this->truckModeOptions = isset($input['TruckModeOptions']) ? CalculateRouteTruckModeOptions::create($input['TruckModeOptions']) : null; + $this->key = $input['Key'] ?? null; parent::__construct($input); } /** * @param array{ * CalculatorName?: string, - * CarModeOptions?: null|CalculateRouteCarModeOptions|array, - * DepartNow?: null|bool, * DeparturePositions?: array[], - * DepartureTime?: null|\DateTimeImmutable|string, * DestinationPositions?: array[], - * DistanceUnit?: null|DistanceUnit::*, - * Key?: null|string, * TravelMode?: null|TravelMode::*, + * DepartureTime?: null|\DateTimeImmutable|string, + * DepartNow?: null|bool, + * DistanceUnit?: null|DistanceUnit::*, + * CarModeOptions?: null|CalculateRouteCarModeOptions|array, * TruckModeOptions?: null|CalculateRouteTruckModeOptions|array, + * Key?: null|string, * '@region'?: string|null, * }|CalculateRouteMatrixRequest $input */ @@ -388,12 +388,6 @@ private function requestBody(): array { $payload = []; - if (null !== $v = $this->carModeOptions) { - $payload['CarModeOptions'] = $v->requestBody(); - } - if (null !== $v = $this->departNow) { - $payload['DepartNow'] = (bool) $v; - } if (null === $v = $this->departurePositions) { throw new InvalidArgument(sprintf('Missing parameter "DeparturePositions" for "%s". The value cannot be null.', __CLASS__)); } @@ -411,9 +405,6 @@ private function requestBody(): array } } - if (null !== $v = $this->departureTime) { - $payload['DepartureTime'] = $v->format(\DateTimeInterface::ATOM); - } if (null === $v = $this->destinationPositions) { throw new InvalidArgument(sprintf('Missing parameter "DestinationPositions" for "%s". The value cannot be null.', __CLASS__)); } @@ -431,18 +422,26 @@ private function requestBody(): array } } + if (null !== $v = $this->travelMode) { + if (!TravelMode::exists($v)) { + throw new InvalidArgument(sprintf('Invalid parameter "TravelMode" for "%s". The value "%s" is not a valid "TravelMode".', __CLASS__, $v)); + } + $payload['TravelMode'] = $v; + } + if (null !== $v = $this->departureTime) { + $payload['DepartureTime'] = $v->format(\DateTimeInterface::ATOM); + } + if (null !== $v = $this->departNow) { + $payload['DepartNow'] = (bool) $v; + } if (null !== $v = $this->distanceUnit) { if (!DistanceUnit::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "DistanceUnit" for "%s". The value "%s" is not a valid "DistanceUnit".', __CLASS__, $v)); } $payload['DistanceUnit'] = $v; } - - if (null !== $v = $this->travelMode) { - if (!TravelMode::exists($v)) { - throw new InvalidArgument(sprintf('Invalid parameter "TravelMode" for "%s". The value "%s" is not a valid "TravelMode".', __CLASS__, $v)); - } - $payload['TravelMode'] = $v; + if (null !== $v = $this->carModeOptions) { + $payload['CarModeOptions'] = $v->requestBody(); } if (null !== $v = $this->truckModeOptions) { $payload['TruckModeOptions'] = $v->requestBody(); diff --git a/src/Input/CalculateRouteRequest.php b/src/Input/CalculateRouteRequest.php index f5955f0..9e16c68 100644 --- a/src/Input/CalculateRouteRequest.php +++ b/src/Input/CalculateRouteRequest.php @@ -14,16 +14,6 @@ final class CalculateRouteRequest extends Input { - /** - * Specifies the desired time of arrival. Uses the given time to calculate the route. Otherwise, the best time of day to - * travel with the best traffic conditions is used to calculate the route. - * - * > ArrivalTime is not supported Esri. - * - * @var \DateTimeImmutable|null - */ - private $arrivalTime; - /** * The name of the route calculator resource that you want to use to calculate the route. * @@ -33,27 +23,6 @@ final class CalculateRouteRequest extends Input */ private $calculatorName; - /** - * Specifies route preferences when traveling by `Car`, such as avoiding routes that use ferries or tolls. - * - * Requirements: `TravelMode` must be specified as `Car`. - * - * @var CalculateRouteCarModeOptions|null - */ - private $carModeOptions; - - /** - * Sets the time of departure as the current time. Uses the current time to calculate a route. Otherwise, the best time - * of day to travel with the best traffic conditions is used to calculate the route. - * - * Default Value: `false` - * - * Valid Values: `false` | `true` - * - * @var bool|null - */ - private $departNow; - /** * The start position for the route. Defined in World Geodetic System (WGS 84) [^1] format: `[longitude, latitude]`. * @@ -74,18 +43,6 @@ final class CalculateRouteRequest extends Input */ private $departurePosition; - /** - * Specifies the desired time of departure. Uses the given time to calculate the route. Otherwise, the best time of day - * to travel with the best traffic conditions is used to calculate the route. - * - * - In ISO 8601 [^1] format: `YYYY-MM-DDThh:mm:ss.sssZ`. For example, `2020–07-2T12:15:20.000Z+01:00` - * - * [^1]: https://www.iso.org/iso-8601-date-and-time-format.html - * - * @var \DateTimeImmutable|null - */ - private $departureTime; - /** * The finish position for the route. Defined in World Geodetic System (WGS 84) [^1] format: `[longitude, latitude]`. * @@ -106,40 +63,27 @@ final class CalculateRouteRequest extends Input private $destinationPosition; /** - * Set the unit system to specify the distance. - * - * Default Value: `Kilometers` - * - * @var DistanceUnit::*|null - */ - private $distanceUnit; - - /** - * Set to include the geometry details in the result for each path between a pair of positions. - * - * Default Value: `false` + * Specifies an ordered list of up to 23 intermediate positions to include along a route between the departure position + * and destination position. * - * Valid Values: `false` | `true` + * - For example, from the `DeparturePosition``[-123.115, 49.285]`, the route follows the order that the waypoint + * positions are given `[[-122.757, 49.0021],[-122.349, 47.620]]` * - * @var bool|null - */ - private $includeLegGeometry; - - /** - * The optional API key [^1] to authorize the request. + * > If you specify a waypoint position that's not located on a road, Amazon Location moves the position to the nearest + * > road [^1]. + * > + * > Specifying more than 23 waypoints returns a `400 ValidationException` error. + * > + * > If Esri is the provider for your route calculator, specifying a route that is longer than 400 km returns a `400 + * > RoutesValidationException` error. * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html + * Valid Values: `[-180 to 180,-90 to 90]` * - * @var string|null - */ - private $key; - - /** - * Specifies the distance to optimize for when calculating a route. + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/snap-to-nearby-road.html * - * @var OptimizationMode::*|null + * @var float[][]|null */ - private $optimizeFor; + private $waypointPositions; /** * Specifies the mode of transport when calculating a route. Used in estimating the speed of travel and road @@ -165,6 +109,59 @@ final class CalculateRouteRequest extends Input */ private $travelMode; + /** + * Specifies the desired time of departure. Uses the given time to calculate the route. Otherwise, the best time of day + * to travel with the best traffic conditions is used to calculate the route. + * + * - In ISO 8601 [^1] format: `YYYY-MM-DDThh:mm:ss.sssZ`. For example, `2020–07-2T12:15:20.000Z+01:00` + * + * [^1]: https://www.iso.org/iso-8601-date-and-time-format.html + * + * @var \DateTimeImmutable|null + */ + private $departureTime; + + /** + * Sets the time of departure as the current time. Uses the current time to calculate a route. Otherwise, the best time + * of day to travel with the best traffic conditions is used to calculate the route. + * + * Default Value: `false` + * + * Valid Values: `false` | `true` + * + * @var bool|null + */ + private $departNow; + + /** + * Set the unit system to specify the distance. + * + * Default Value: `Kilometers` + * + * @var DistanceUnit::*|null + */ + private $distanceUnit; + + /** + * Set to include the geometry details in the result for each path between a pair of positions. + * + * Default Value: `false` + * + * Valid Values: `false` | `true` + * + * @var bool|null + */ + private $includeLegGeometry; + + /** + * Specifies route preferences when traveling by `Car`, such as avoiding routes that use ferries or tolls. + * + * Requirements: `TravelMode` must be specified as `Car`. + * + * @var CalculateRouteCarModeOptions|null + */ + private $carModeOptions; + /** * Specifies route preferences when traveling by `Truck`, such as avoiding routes that use ferries or tolls, and truck * specifications to consider when choosing an optimal road. @@ -176,82 +173,85 @@ final class CalculateRouteRequest extends Input private $truckModeOptions; /** - * Specifies an ordered list of up to 23 intermediate positions to include along a route between the departure position - * and destination position. + * Specifies the desired time of arrival. Uses the given time to calculate the route. Otherwise, the best time of day to + * travel with the best traffic conditions is used to calculate the route. * - * - For example, from the `DeparturePosition``[-123.115, 49.285]`, the route follows the order that the waypoint - * positions are given `[[-122.757, 49.0021],[-122.349, 47.620]]` + * > ArrivalTime is not supported Esri. * - * > If you specify a waypoint position that's not located on a road, Amazon Location moves the position to the nearest - * > road [^1]. - * > - * > Specifying more than 23 waypoints returns a `400 ValidationException` error. - * > - * > If Esri is the provider for your route calculator, specifying a route that is longer than 400 km returns a `400 - * > RoutesValidationException` error. + * @var \DateTimeImmutable|null + */ + private $arrivalTime; + + /** + * Specifies the distance to optimize for when calculating a route. * - * Valid Values: `[-180 to 180,-90 to 90]` + * @var OptimizationMode::*|null + */ + private $optimizeFor; + + /** + * The optional API key [^1] to authorize the request. * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/snap-to-nearby-road.html + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html * - * @var float[][]|null + * @var string|null */ - private $waypointPositions; + private $key; /** * @param array{ - * ArrivalTime?: null|\DateTimeImmutable|string, * CalculatorName?: string, - * CarModeOptions?: null|CalculateRouteCarModeOptions|array, - * DepartNow?: null|bool, * DeparturePosition?: float[], - * DepartureTime?: null|\DateTimeImmutable|string, * DestinationPosition?: float[], + * WaypointPositions?: null|array[], + * TravelMode?: null|TravelMode::*, + * DepartureTime?: null|\DateTimeImmutable|string, + * DepartNow?: null|bool, * DistanceUnit?: null|DistanceUnit::*, * IncludeLegGeometry?: null|bool, - * Key?: null|string, - * OptimizeFor?: null|OptimizationMode::*, - * TravelMode?: null|TravelMode::*, + * CarModeOptions?: null|CalculateRouteCarModeOptions|array, * TruckModeOptions?: null|CalculateRouteTruckModeOptions|array, - * WaypointPositions?: null|array[], + * ArrivalTime?: null|\DateTimeImmutable|string, + * OptimizeFor?: null|OptimizationMode::*, + * Key?: null|string, * '@region'?: string|null, * } $input */ public function __construct(array $input = []) { - $this->arrivalTime = !isset($input['ArrivalTime']) ? null : ($input['ArrivalTime'] instanceof \DateTimeImmutable ? $input['ArrivalTime'] : new \DateTimeImmutable($input['ArrivalTime'])); $this->calculatorName = $input['CalculatorName'] ?? null; - $this->carModeOptions = isset($input['CarModeOptions']) ? CalculateRouteCarModeOptions::create($input['CarModeOptions']) : null; - $this->departNow = $input['DepartNow'] ?? null; $this->departurePosition = $input['DeparturePosition'] ?? null; - $this->departureTime = !isset($input['DepartureTime']) ? null : ($input['DepartureTime'] instanceof \DateTimeImmutable ? $input['DepartureTime'] : new \DateTimeImmutable($input['DepartureTime'])); $this->destinationPosition = $input['DestinationPosition'] ?? null; + $this->waypointPositions = $input['WaypointPositions'] ?? null; + $this->travelMode = $input['TravelMode'] ?? null; + $this->departureTime = !isset($input['DepartureTime']) ? null : ($input['DepartureTime'] instanceof \DateTimeImmutable ? $input['DepartureTime'] : new \DateTimeImmutable($input['DepartureTime'])); + $this->departNow = $input['DepartNow'] ?? null; $this->distanceUnit = $input['DistanceUnit'] ?? null; $this->includeLegGeometry = $input['IncludeLegGeometry'] ?? null; - $this->key = $input['Key'] ?? null; - $this->optimizeFor = $input['OptimizeFor'] ?? null; - $this->travelMode = $input['TravelMode'] ?? null; + $this->carModeOptions = isset($input['CarModeOptions']) ? CalculateRouteCarModeOptions::create($input['CarModeOptions']) : null; $this->truckModeOptions = isset($input['TruckModeOptions']) ? CalculateRouteTruckModeOptions::create($input['TruckModeOptions']) : null; - $this->waypointPositions = $input['WaypointPositions'] ?? null; + $this->arrivalTime = !isset($input['ArrivalTime']) ? null : ($input['ArrivalTime'] instanceof \DateTimeImmutable ? $input['ArrivalTime'] : new \DateTimeImmutable($input['ArrivalTime'])); + $this->optimizeFor = $input['OptimizeFor'] ?? null; + $this->key = $input['Key'] ?? null; parent::__construct($input); } /** * @param array{ - * ArrivalTime?: null|\DateTimeImmutable|string, * CalculatorName?: string, - * CarModeOptions?: null|CalculateRouteCarModeOptions|array, - * DepartNow?: null|bool, * DeparturePosition?: float[], - * DepartureTime?: null|\DateTimeImmutable|string, * DestinationPosition?: float[], + * WaypointPositions?: null|array[], + * TravelMode?: null|TravelMode::*, + * DepartureTime?: null|\DateTimeImmutable|string, + * DepartNow?: null|bool, * DistanceUnit?: null|DistanceUnit::*, * IncludeLegGeometry?: null|bool, - * Key?: null|string, - * OptimizeFor?: null|OptimizationMode::*, - * TravelMode?: null|TravelMode::*, + * CarModeOptions?: null|CalculateRouteCarModeOptions|array, * TruckModeOptions?: null|CalculateRouteTruckModeOptions|array, - * WaypointPositions?: null|array[], + * ArrivalTime?: null|\DateTimeImmutable|string, + * OptimizeFor?: null|OptimizationMode::*, + * Key?: null|string, * '@region'?: string|null, * }|CalculateRouteRequest $input */ @@ -500,16 +500,7 @@ public function setWaypointPositions(array $value): self private function requestBody(): array { $payload = []; - if (null !== $v = $this->arrivalTime) { - $payload['ArrivalTime'] = $v->format(\DateTimeInterface::ATOM); - } - if (null !== $v = $this->carModeOptions) { - $payload['CarModeOptions'] = $v->requestBody(); - } - if (null !== $v = $this->departNow) { - $payload['DepartNow'] = (bool) $v; - } if (null === $v = $this->departurePosition) { throw new InvalidArgument(sprintf('Missing parameter "DeparturePosition" for "%s". The value cannot be null.', __CLASS__)); } @@ -521,9 +512,6 @@ private function requestBody(): array $payload['DeparturePosition'][$index] = $listValue; } - if (null !== $v = $this->departureTime) { - $payload['DepartureTime'] = $v->format(\DateTimeInterface::ATOM); - } if (null === $v = $this->destinationPosition) { throw new InvalidArgument(sprintf('Missing parameter "DestinationPosition" for "%s". The value cannot be null.', __CLASS__)); } @@ -535,6 +523,32 @@ private function requestBody(): array $payload['DestinationPosition'][$index] = $listValue; } + if (null !== $v = $this->waypointPositions) { + $index = -1; + $payload['WaypointPositions'] = []; + foreach ($v as $listValue) { + ++$index; + + $index1 = -1; + $payload['WaypointPositions'][$index] = []; + foreach ($listValue as $listValue1) { + ++$index1; + $payload['WaypointPositions'][$index][$index1] = $listValue1; + } + } + } + if (null !== $v = $this->travelMode) { + if (!TravelMode::exists($v)) { + throw new InvalidArgument(sprintf('Invalid parameter "TravelMode" for "%s". The value "%s" is not a valid "TravelMode".', __CLASS__, $v)); + } + $payload['TravelMode'] = $v; + } + if (null !== $v = $this->departureTime) { + $payload['DepartureTime'] = $v->format(\DateTimeInterface::ATOM); + } + if (null !== $v = $this->departNow) { + $payload['DepartNow'] = (bool) $v; + } if (null !== $v = $this->distanceUnit) { if (!DistanceUnit::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "DistanceUnit" for "%s". The value "%s" is not a valid "DistanceUnit".', __CLASS__, $v)); @@ -544,35 +558,20 @@ private function requestBody(): array if (null !== $v = $this->includeLegGeometry) { $payload['IncludeLegGeometry'] = (bool) $v; } - - if (null !== $v = $this->optimizeFor) { - if (!OptimizationMode::exists($v)) { - throw new InvalidArgument(sprintf('Invalid parameter "OptimizeFor" for "%s". The value "%s" is not a valid "OptimizationMode".', __CLASS__, $v)); - } - $payload['OptimizeFor'] = $v; - } - if (null !== $v = $this->travelMode) { - if (!TravelMode::exists($v)) { - throw new InvalidArgument(sprintf('Invalid parameter "TravelMode" for "%s". The value "%s" is not a valid "TravelMode".', __CLASS__, $v)); - } - $payload['TravelMode'] = $v; + if (null !== $v = $this->carModeOptions) { + $payload['CarModeOptions'] = $v->requestBody(); } if (null !== $v = $this->truckModeOptions) { $payload['TruckModeOptions'] = $v->requestBody(); } - if (null !== $v = $this->waypointPositions) { - $index = -1; - $payload['WaypointPositions'] = []; - foreach ($v as $listValue) { - ++$index; - - $index1 = -1; - $payload['WaypointPositions'][$index] = []; - foreach ($listValue as $listValue1) { - ++$index1; - $payload['WaypointPositions'][$index][$index1] = $listValue1; - } + if (null !== $v = $this->arrivalTime) { + $payload['ArrivalTime'] = $v->format(\DateTimeInterface::ATOM); + } + if (null !== $v = $this->optimizeFor) { + if (!OptimizationMode::exists($v)) { + throw new InvalidArgument(sprintf('Invalid parameter "OptimizeFor" for "%s". The value "%s" is not a valid "OptimizationMode".', __CLASS__, $v)); } + $payload['OptimizeFor'] = $v; } return $payload; diff --git a/src/Input/SearchPlaceIndexForPositionRequest.php b/src/Input/SearchPlaceIndexForPositionRequest.php index 9a50c73..5c3e01d 100644 --- a/src/Input/SearchPlaceIndexForPositionRequest.php +++ b/src/Input/SearchPlaceIndexForPositionRequest.php @@ -19,13 +19,27 @@ final class SearchPlaceIndexForPositionRequest extends Input private $indexName; /** - * The optional API key [^1] to authorize the request. + * Specifies the longitude and latitude of the position to query. * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html + * This parameter must contain a pair of numbers. The first number represents the X coordinate, or longitude; the second + * number represents the Y coordinate, or latitude. * - * @var string|null + * For example, `[-123.1174, 49.2847]` represents a position with longitude `-123.1174` and latitude `49.2847`. + * + * @required + * + * @var float[]|null */ - private $key; + private $position; + + /** + * An optional parameter. The maximum number of results returned per request. + * + * Default value: `50` + * + * @var int|null + */ + private $maxResults; /** * The preferred language used to return results. The value must be a valid BCP 47 [^1] language tag, for example, `en` @@ -50,55 +64,41 @@ final class SearchPlaceIndexForPositionRequest extends Input private $language; /** - * An optional parameter. The maximum number of results returned per request. - * - * Default value: `50` - * - * @var int|null - */ - private $maxResults; - - /** - * Specifies the longitude and latitude of the position to query. - * - * This parameter must contain a pair of numbers. The first number represents the X coordinate, or longitude; the second - * number represents the Y coordinate, or latitude. - * - * For example, `[-123.1174, 49.2847]` represents a position with longitude `-123.1174` and latitude `49.2847`. + * The optional API key [^1] to authorize the request. * - * @required + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html * - * @var float[]|null + * @var string|null */ - private $position; + private $key; /** * @param array{ * IndexName?: string, - * Key?: null|string, - * Language?: null|string, - * MaxResults?: null|int, * Position?: float[], + * MaxResults?: null|int, + * Language?: null|string, + * Key?: null|string, * '@region'?: string|null, * } $input */ public function __construct(array $input = []) { $this->indexName = $input['IndexName'] ?? null; - $this->key = $input['Key'] ?? null; - $this->language = $input['Language'] ?? null; - $this->maxResults = $input['MaxResults'] ?? null; $this->position = $input['Position'] ?? null; + $this->maxResults = $input['MaxResults'] ?? null; + $this->language = $input['Language'] ?? null; + $this->key = $input['Key'] ?? null; parent::__construct($input); } /** * @param array{ * IndexName?: string, - * Key?: null|string, - * Language?: null|string, - * MaxResults?: null|int, * Position?: float[], + * MaxResults?: null|int, + * Language?: null|string, + * Key?: null|string, * '@region'?: string|null, * }|SearchPlaceIndexForPositionRequest $input */ @@ -210,12 +210,6 @@ private function requestBody(): array { $payload = []; - if (null !== $v = $this->language) { - $payload['Language'] = $v; - } - if (null !== $v = $this->maxResults) { - $payload['MaxResults'] = $v; - } if (null === $v = $this->position) { throw new InvalidArgument(sprintf('Missing parameter "Position" for "%s". The value cannot be null.', __CLASS__)); } @@ -227,6 +221,13 @@ private function requestBody(): array $payload['Position'][$index] = $listValue; } + if (null !== $v = $this->maxResults) { + $payload['MaxResults'] = $v; + } + if (null !== $v = $this->language) { + $payload['Language'] = $v; + } + return $payload; } } diff --git a/src/Input/SearchPlaceIndexForTextRequest.php b/src/Input/SearchPlaceIndexForTextRequest.php index 1ab05aa..8497d35 100644 --- a/src/Input/SearchPlaceIndexForTextRequest.php +++ b/src/Input/SearchPlaceIndexForTextRequest.php @@ -9,6 +9,24 @@ final class SearchPlaceIndexForTextRequest extends Input { + /** + * The name of the place index resource you want to use for the search. + * + * @required + * + * @var string|null + */ + private $indexName; + + /** + * The address, name, city, or region to be used in the search in free-form text format. For example, `123 Any Street`. + * + * @required + * + * @var string|null + */ + private $text; + /** * An optional parameter that indicates a preference for places that are closer to a specified position. * @@ -42,19 +60,6 @@ final class SearchPlaceIndexForTextRequest extends Input */ private $filterBbox; - /** - * A list of one or more Amazon Location categories to filter the returned places. If you include more than one - * category, the results will include results that match *any* of the categories listed. - * - * For more information about using categories, including a list of Amazon Location categories, see Categories and - * filtering [^1], in the *Amazon Location Service Developer Guide*. - * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/category-filtering.html - * - * @var string[]|null - */ - private $filterCategories; - /** * An optional parameter that limits the search results by returning only places that are in a specified list of * countries. @@ -69,22 +74,13 @@ final class SearchPlaceIndexForTextRequest extends Input private $filterCountries; /** - * The name of the place index resource you want to use for the search. - * - * @required - * - * @var string|null - */ - private $indexName; - - /** - * The optional API key [^1] to authorize the request. + * An optional parameter. The maximum number of results returned per request. * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html + * The default: `50` * - * @var string|null + * @var int|null */ - private $key; + private $maxResults; /** * The preferred language used to return results. The value must be a valid BCP 47 [^1] language tag, for example, `en` @@ -109,62 +105,66 @@ final class SearchPlaceIndexForTextRequest extends Input private $language; /** - * An optional parameter. The maximum number of results returned per request. + * A list of one or more Amazon Location categories to filter the returned places. If you include more than one + * category, the results will include results that match *any* of the categories listed. * - * The default: `50` + * For more information about using categories, including a list of Amazon Location categories, see Categories and + * filtering [^1], in the *Amazon Location Service Developer Guide*. * - * @var int|null + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/category-filtering.html + * + * @var string[]|null */ - private $maxResults; + private $filterCategories; /** - * The address, name, city, or region to be used in the search in free-form text format. For example, `123 Any Street`. + * The optional API key [^1] to authorize the request. * - * @required + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html * * @var string|null */ - private $text; + private $key; /** * @param array{ + * IndexName?: string, + * Text?: string, * BiasPosition?: null|float[], * FilterBBox?: null|float[], - * FilterCategories?: null|string[], * FilterCountries?: null|string[], - * IndexName?: string, - * Key?: null|string, - * Language?: null|string, * MaxResults?: null|int, - * Text?: string, + * Language?: null|string, + * FilterCategories?: null|string[], + * Key?: null|string, * '@region'?: string|null, * } $input */ public function __construct(array $input = []) { + $this->indexName = $input['IndexName'] ?? null; + $this->text = $input['Text'] ?? null; $this->biasPosition = $input['BiasPosition'] ?? null; $this->filterBbox = $input['FilterBBox'] ?? null; - $this->filterCategories = $input['FilterCategories'] ?? null; $this->filterCountries = $input['FilterCountries'] ?? null; - $this->indexName = $input['IndexName'] ?? null; - $this->key = $input['Key'] ?? null; - $this->language = $input['Language'] ?? null; $this->maxResults = $input['MaxResults'] ?? null; - $this->text = $input['Text'] ?? null; + $this->language = $input['Language'] ?? null; + $this->filterCategories = $input['FilterCategories'] ?? null; + $this->key = $input['Key'] ?? null; parent::__construct($input); } /** * @param array{ + * IndexName?: string, + * Text?: string, * BiasPosition?: null|float[], * FilterBBox?: null|float[], - * FilterCategories?: null|string[], * FilterCountries?: null|string[], - * IndexName?: string, - * Key?: null|string, - * Language?: null|string, * MaxResults?: null|int, - * Text?: string, + * Language?: null|string, + * FilterCategories?: null|string[], + * Key?: null|string, * '@region'?: string|null, * }|SearchPlaceIndexForTextRequest $input */ @@ -341,6 +341,11 @@ public function setText(?string $value): self private function requestBody(): array { $payload = []; + + if (null === $v = $this->text) { + throw new InvalidArgument(sprintf('Missing parameter "Text" for "%s". The value cannot be null.', __CLASS__)); + } + $payload['Text'] = $v; if (null !== $v = $this->biasPosition) { $index = -1; $payload['BiasPosition'] = []; @@ -357,14 +362,6 @@ private function requestBody(): array $payload['FilterBBox'][$index] = $listValue; } } - if (null !== $v = $this->filterCategories) { - $index = -1; - $payload['FilterCategories'] = []; - foreach ($v as $listValue) { - ++$index; - $payload['FilterCategories'][$index] = $listValue; - } - } if (null !== $v = $this->filterCountries) { $index = -1; $payload['FilterCountries'] = []; @@ -373,17 +370,20 @@ private function requestBody(): array $payload['FilterCountries'][$index] = $listValue; } } - - if (null !== $v = $this->language) { - $payload['Language'] = $v; - } if (null !== $v = $this->maxResults) { $payload['MaxResults'] = $v; } - if (null === $v = $this->text) { - throw new InvalidArgument(sprintf('Missing parameter "Text" for "%s". The value cannot be null.', __CLASS__)); + if (null !== $v = $this->language) { + $payload['Language'] = $v; + } + if (null !== $v = $this->filterCategories) { + $index = -1; + $payload['FilterCategories'] = []; + foreach ($v as $listValue) { + ++$index; + $payload['FilterCategories'][$index] = $listValue; + } } - $payload['Text'] = $v; return $payload; } diff --git a/src/LocationServiceClient.php b/src/LocationServiceClient.php index 69354fe..f7270c9 100644 --- a/src/LocationServiceClient.php +++ b/src/LocationServiceClient.php @@ -59,20 +59,20 @@ class LocationServiceClient extends AbstractApi * @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-geo-2020-11-19.html#calculateroute * * @param array{ - * ArrivalTime?: null|\DateTimeImmutable|string, * CalculatorName: string, - * CarModeOptions?: null|CalculateRouteCarModeOptions|array, - * DepartNow?: null|bool, * DeparturePosition: float[], - * DepartureTime?: null|\DateTimeImmutable|string, * DestinationPosition: float[], + * WaypointPositions?: null|array[], + * TravelMode?: null|TravelMode::*, + * DepartureTime?: null|\DateTimeImmutable|string, + * DepartNow?: null|bool, * DistanceUnit?: null|DistanceUnit::*, * IncludeLegGeometry?: null|bool, - * Key?: null|string, - * OptimizeFor?: null|OptimizationMode::*, - * TravelMode?: null|TravelMode::*, + * CarModeOptions?: null|CalculateRouteCarModeOptions|array, * TruckModeOptions?: null|CalculateRouteTruckModeOptions|array, - * WaypointPositions?: null|array[], + * ArrivalTime?: null|\DateTimeImmutable|string, + * OptimizeFor?: null|OptimizationMode::*, + * Key?: null|string, * '@region'?: string|null, * }|CalculateRouteRequest $input * @@ -133,15 +133,15 @@ public function calculateRoute($input): CalculateRouteResponse * * @param array{ * CalculatorName: string, - * CarModeOptions?: null|CalculateRouteCarModeOptions|array, - * DepartNow?: null|bool, * DeparturePositions: array[], - * DepartureTime?: null|\DateTimeImmutable|string, * DestinationPositions: array[], - * DistanceUnit?: null|DistanceUnit::*, - * Key?: null|string, * TravelMode?: null|TravelMode::*, + * DepartureTime?: null|\DateTimeImmutable|string, + * DepartNow?: null|bool, + * DistanceUnit?: null|DistanceUnit::*, + * CarModeOptions?: null|CalculateRouteCarModeOptions|array, * TruckModeOptions?: null|CalculateRouteTruckModeOptions|array, + * Key?: null|string, * '@region'?: string|null, * }|CalculateRouteMatrixRequest $input * @@ -174,10 +174,10 @@ public function calculateRouteMatrix($input): CalculateRouteMatrixResponse * * @param array{ * IndexName: string, - * Key?: null|string, - * Language?: null|string, - * MaxResults?: null|int, * Position: float[], + * MaxResults?: null|int, + * Language?: null|string, + * Key?: null|string, * '@region'?: string|null, * }|SearchPlaceIndexForPositionRequest $input * @@ -217,15 +217,15 @@ public function searchPlaceIndexForPosition($input): SearchPlaceIndexForPosition * @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-geo-2020-11-19.html#searchplaceindexfortext * * @param array{ + * IndexName: string, + * Text: string, * BiasPosition?: null|float[], * FilterBBox?: null|float[], - * FilterCategories?: null|string[], * FilterCountries?: null|string[], - * IndexName: string, - * Key?: null|string, - * Language?: null|string, * MaxResults?: null|int, - * Text: string, + * Language?: null|string, + * FilterCategories?: null|string[], + * Key?: null|string, * '@region'?: string|null, * }|SearchPlaceIndexForTextRequest $input * diff --git a/src/Result/CalculateRouteMatrixResponse.php b/src/Result/CalculateRouteMatrixResponse.php index 794710a..73b189f 100644 --- a/src/Result/CalculateRouteMatrixResponse.php +++ b/src/Result/CalculateRouteMatrixResponse.php @@ -123,9 +123,9 @@ private function populateResultCalculateRouteMatrixSummary(array $json): Calcula { return new CalculateRouteMatrixSummary([ 'DataSource' => (string) $json['DataSource'], - 'DistanceUnit' => (string) $json['DistanceUnit'], - 'ErrorCount' => (int) $json['ErrorCount'], 'RouteCount' => (int) $json['RouteCount'], + 'ErrorCount' => (int) $json['ErrorCount'], + 'DistanceUnit' => (string) $json['DistanceUnit'], ]); } diff --git a/src/Result/CalculateRouteResponse.php b/src/Result/CalculateRouteResponse.php index b754075..adbae45 100644 --- a/src/Result/CalculateRouteResponse.php +++ b/src/Result/CalculateRouteResponse.php @@ -90,22 +90,22 @@ private function populateResultBoundingBox(array $json): array private function populateResultCalculateRouteSummary(array $json): CalculateRouteSummary { return new CalculateRouteSummary([ + 'RouteBBox' => $this->populateResultBoundingBox($json['RouteBBox']), 'DataSource' => (string) $json['DataSource'], 'Distance' => (float) $json['Distance'], - 'DistanceUnit' => (string) $json['DistanceUnit'], 'DurationSeconds' => (float) $json['DurationSeconds'], - 'RouteBBox' => $this->populateResultBoundingBox($json['RouteBBox']), + 'DistanceUnit' => (string) $json['DistanceUnit'], ]); } private function populateResultLeg(array $json): Leg { return new Leg([ + 'StartPosition' => $this->populateResultPosition($json['StartPosition']), + 'EndPosition' => $this->populateResultPosition($json['EndPosition']), 'Distance' => (float) $json['Distance'], 'DurationSeconds' => (float) $json['DurationSeconds'], - 'EndPosition' => $this->populateResultPosition($json['EndPosition']), 'Geometry' => empty($json['Geometry']) ? null : $this->populateResultLegGeometry($json['Geometry']), - 'StartPosition' => $this->populateResultPosition($json['StartPosition']), 'Steps' => $this->populateResultStepList($json['Steps']), ]); } @@ -162,11 +162,11 @@ private function populateResultPosition(array $json): array private function populateResultStep(array $json): Step { return new Step([ + 'StartPosition' => $this->populateResultPosition($json['StartPosition']), + 'EndPosition' => $this->populateResultPosition($json['EndPosition']), 'Distance' => (float) $json['Distance'], 'DurationSeconds' => (float) $json['DurationSeconds'], - 'EndPosition' => $this->populateResultPosition($json['EndPosition']), 'GeometryOffset' => isset($json['GeometryOffset']) ? (int) $json['GeometryOffset'] : null, - 'StartPosition' => $this->populateResultPosition($json['StartPosition']), ]); } diff --git a/src/Result/SearchPlaceIndexForPositionResponse.php b/src/Result/SearchPlaceIndexForPositionResponse.php index bfb900c..c8e168b 100644 --- a/src/Result/SearchPlaceIndexForPositionResponse.php +++ b/src/Result/SearchPlaceIndexForPositionResponse.php @@ -12,14 +12,6 @@ class SearchPlaceIndexForPositionResponse extends Result { - /** - * Returns a list of Places closest to the specified position. Each result contains additional information about the - * Places returned. - * - * @var SearchForPositionResult[] - */ - private $results; - /** * Contains a summary of the request. Echoes the input values for `Position`, `Language`, `MaxResults`, and the * `DataSource` of the place index. @@ -28,6 +20,14 @@ class SearchPlaceIndexForPositionResponse extends Result */ private $summary; + /** + * Returns a list of Places closest to the specified position. Each result contains additional information about the + * Places returned. + * + * @var SearchForPositionResult[] + */ + private $results; + /** * @return SearchForPositionResult[] */ @@ -49,30 +49,30 @@ protected function populateResult(Response $response): void { $data = $response->toArray(); - $this->results = $this->populateResultSearchForPositionResultList($data['Results'] ?? []); $this->summary = $this->populateResultSearchPlaceIndexForPositionSummary($data['Summary']); + $this->results = $this->populateResultSearchForPositionResultList($data['Results'] ?? []); } private function populateResultPlace(array $json): Place { return new Place([ - 'AddressNumber' => isset($json['AddressNumber']) ? (string) $json['AddressNumber'] : null, - 'Categories' => !isset($json['Categories']) ? null : $this->populateResultPlaceCategoryList($json['Categories']), - 'Country' => isset($json['Country']) ? (string) $json['Country'] : null, - 'Geometry' => $this->populateResultPlaceGeometry($json['Geometry']), - 'Interpolated' => isset($json['Interpolated']) ? filter_var($json['Interpolated'], \FILTER_VALIDATE_BOOLEAN) : null, 'Label' => isset($json['Label']) ? (string) $json['Label'] : null, - 'Municipality' => isset($json['Municipality']) ? (string) $json['Municipality'] : null, - 'Neighborhood' => isset($json['Neighborhood']) ? (string) $json['Neighborhood'] : null, - 'PostalCode' => isset($json['PostalCode']) ? (string) $json['PostalCode'] : null, - 'Region' => isset($json['Region']) ? (string) $json['Region'] : null, + 'Geometry' => $this->populateResultPlaceGeometry($json['Geometry']), + 'AddressNumber' => isset($json['AddressNumber']) ? (string) $json['AddressNumber'] : null, 'Street' => isset($json['Street']) ? (string) $json['Street'] : null, - 'SubMunicipality' => isset($json['SubMunicipality']) ? (string) $json['SubMunicipality'] : null, + 'Neighborhood' => isset($json['Neighborhood']) ? (string) $json['Neighborhood'] : null, + 'Municipality' => isset($json['Municipality']) ? (string) $json['Municipality'] : null, 'SubRegion' => isset($json['SubRegion']) ? (string) $json['SubRegion'] : null, - 'SupplementalCategories' => !isset($json['SupplementalCategories']) ? null : $this->populateResultPlaceSupplementalCategoryList($json['SupplementalCategories']), + 'Region' => isset($json['Region']) ? (string) $json['Region'] : null, + 'Country' => isset($json['Country']) ? (string) $json['Country'] : null, + 'PostalCode' => isset($json['PostalCode']) ? (string) $json['PostalCode'] : null, + 'Interpolated' => isset($json['Interpolated']) ? filter_var($json['Interpolated'], \FILTER_VALIDATE_BOOLEAN) : null, 'TimeZone' => empty($json['TimeZone']) ? null : $this->populateResultTimeZone($json['TimeZone']), - 'UnitNumber' => isset($json['UnitNumber']) ? (string) $json['UnitNumber'] : null, 'UnitType' => isset($json['UnitType']) ? (string) $json['UnitType'] : null, + 'UnitNumber' => isset($json['UnitNumber']) ? (string) $json['UnitNumber'] : null, + 'Categories' => !isset($json['Categories']) ? null : $this->populateResultPlaceCategoryList($json['Categories']), + 'SupplementalCategories' => !isset($json['SupplementalCategories']) ? null : $this->populateResultPlaceSupplementalCategoryList($json['SupplementalCategories']), + 'SubMunicipality' => isset($json['SubMunicipality']) ? (string) $json['SubMunicipality'] : null, ]); } @@ -134,8 +134,8 @@ private function populateResultPosition(array $json): array private function populateResultSearchForPositionResult(array $json): SearchForPositionResult { return new SearchForPositionResult([ - 'Distance' => (float) $json['Distance'], 'Place' => $this->populateResultPlace($json['Place']), + 'Distance' => (float) $json['Distance'], 'PlaceId' => isset($json['PlaceId']) ? (string) $json['PlaceId'] : null, ]); } @@ -156,10 +156,10 @@ private function populateResultSearchForPositionResultList(array $json): array private function populateResultSearchPlaceIndexForPositionSummary(array $json): SearchPlaceIndexForPositionSummary { return new SearchPlaceIndexForPositionSummary([ + 'Position' => $this->populateResultPosition($json['Position']), + 'MaxResults' => isset($json['MaxResults']) ? (int) $json['MaxResults'] : null, 'DataSource' => (string) $json['DataSource'], 'Language' => isset($json['Language']) ? (string) $json['Language'] : null, - 'MaxResults' => isset($json['MaxResults']) ? (int) $json['MaxResults'] : null, - 'Position' => $this->populateResultPosition($json['Position']), ]); } diff --git a/src/Result/SearchPlaceIndexForTextResponse.php b/src/Result/SearchPlaceIndexForTextResponse.php index 3b44b75..ff97fe3 100644 --- a/src/Result/SearchPlaceIndexForTextResponse.php +++ b/src/Result/SearchPlaceIndexForTextResponse.php @@ -12,6 +12,15 @@ class SearchPlaceIndexForTextResponse extends Result { + /** + * Contains a summary of the request. Echoes the input values for `BiasPosition`, `FilterBBox`, `FilterCountries`, + * `Language`, `MaxResults`, and `Text`. Also includes the `DataSource` of the place index and the bounding box, + * `ResultBBox`, which surrounds the search results. + * + * @var SearchPlaceIndexForTextSummary + */ + private $summary; + /** * A list of Places matching the input text. Each result contains additional information about the specific point of * interest. @@ -23,15 +32,6 @@ class SearchPlaceIndexForTextResponse extends Result */ private $results; - /** - * Contains a summary of the request. Echoes the input values for `BiasPosition`, `FilterBBox`, `FilterCountries`, - * `Language`, `MaxResults`, and `Text`. Also includes the `DataSource` of the place index and the bounding box, - * `ResultBBox`, which surrounds the search results. - * - * @var SearchPlaceIndexForTextSummary - */ - private $summary; - /** * @return SearchForTextResult[] */ @@ -53,8 +53,8 @@ protected function populateResult(Response $response): void { $data = $response->toArray(); - $this->results = $this->populateResultSearchForTextResultList($data['Results'] ?? []); $this->summary = $this->populateResultSearchPlaceIndexForTextSummary($data['Summary']); + $this->results = $this->populateResultSearchForTextResultList($data['Results'] ?? []); } /** @@ -108,23 +108,23 @@ private function populateResultFilterPlaceCategoryList(array $json): array private function populateResultPlace(array $json): Place { return new Place([ - 'AddressNumber' => isset($json['AddressNumber']) ? (string) $json['AddressNumber'] : null, - 'Categories' => !isset($json['Categories']) ? null : $this->populateResultPlaceCategoryList($json['Categories']), - 'Country' => isset($json['Country']) ? (string) $json['Country'] : null, - 'Geometry' => $this->populateResultPlaceGeometry($json['Geometry']), - 'Interpolated' => isset($json['Interpolated']) ? filter_var($json['Interpolated'], \FILTER_VALIDATE_BOOLEAN) : null, 'Label' => isset($json['Label']) ? (string) $json['Label'] : null, - 'Municipality' => isset($json['Municipality']) ? (string) $json['Municipality'] : null, - 'Neighborhood' => isset($json['Neighborhood']) ? (string) $json['Neighborhood'] : null, - 'PostalCode' => isset($json['PostalCode']) ? (string) $json['PostalCode'] : null, - 'Region' => isset($json['Region']) ? (string) $json['Region'] : null, + 'Geometry' => $this->populateResultPlaceGeometry($json['Geometry']), + 'AddressNumber' => isset($json['AddressNumber']) ? (string) $json['AddressNumber'] : null, 'Street' => isset($json['Street']) ? (string) $json['Street'] : null, - 'SubMunicipality' => isset($json['SubMunicipality']) ? (string) $json['SubMunicipality'] : null, + 'Neighborhood' => isset($json['Neighborhood']) ? (string) $json['Neighborhood'] : null, + 'Municipality' => isset($json['Municipality']) ? (string) $json['Municipality'] : null, 'SubRegion' => isset($json['SubRegion']) ? (string) $json['SubRegion'] : null, - 'SupplementalCategories' => !isset($json['SupplementalCategories']) ? null : $this->populateResultPlaceSupplementalCategoryList($json['SupplementalCategories']), + 'Region' => isset($json['Region']) ? (string) $json['Region'] : null, + 'Country' => isset($json['Country']) ? (string) $json['Country'] : null, + 'PostalCode' => isset($json['PostalCode']) ? (string) $json['PostalCode'] : null, + 'Interpolated' => isset($json['Interpolated']) ? filter_var($json['Interpolated'], \FILTER_VALIDATE_BOOLEAN) : null, 'TimeZone' => empty($json['TimeZone']) ? null : $this->populateResultTimeZone($json['TimeZone']), - 'UnitNumber' => isset($json['UnitNumber']) ? (string) $json['UnitNumber'] : null, 'UnitType' => isset($json['UnitType']) ? (string) $json['UnitType'] : null, + 'UnitNumber' => isset($json['UnitNumber']) ? (string) $json['UnitNumber'] : null, + 'Categories' => !isset($json['Categories']) ? null : $this->populateResultPlaceCategoryList($json['Categories']), + 'SupplementalCategories' => !isset($json['SupplementalCategories']) ? null : $this->populateResultPlaceSupplementalCategoryList($json['SupplementalCategories']), + 'SubMunicipality' => isset($json['SubMunicipality']) ? (string) $json['SubMunicipality'] : null, ]); } @@ -186,10 +186,10 @@ private function populateResultPosition(array $json): array private function populateResultSearchForTextResult(array $json): SearchForTextResult { return new SearchForTextResult([ - 'Distance' => isset($json['Distance']) ? (float) $json['Distance'] : null, 'Place' => $this->populateResultPlace($json['Place']), - 'PlaceId' => isset($json['PlaceId']) ? (string) $json['PlaceId'] : null, + 'Distance' => isset($json['Distance']) ? (float) $json['Distance'] : null, 'Relevance' => isset($json['Relevance']) ? (float) $json['Relevance'] : null, + 'PlaceId' => isset($json['PlaceId']) ? (string) $json['PlaceId'] : null, ]); } @@ -209,15 +209,15 @@ private function populateResultSearchForTextResultList(array $json): array private function populateResultSearchPlaceIndexForTextSummary(array $json): SearchPlaceIndexForTextSummary { return new SearchPlaceIndexForTextSummary([ + 'Text' => (string) $json['Text'], 'BiasPosition' => !isset($json['BiasPosition']) ? null : $this->populateResultPosition($json['BiasPosition']), - 'DataSource' => (string) $json['DataSource'], 'FilterBBox' => !isset($json['FilterBBox']) ? null : $this->populateResultBoundingBox($json['FilterBBox']), - 'FilterCategories' => !isset($json['FilterCategories']) ? null : $this->populateResultFilterPlaceCategoryList($json['FilterCategories']), 'FilterCountries' => !isset($json['FilterCountries']) ? null : $this->populateResultCountryCodeList($json['FilterCountries']), - 'Language' => isset($json['Language']) ? (string) $json['Language'] : null, 'MaxResults' => isset($json['MaxResults']) ? (int) $json['MaxResults'] : null, 'ResultBBox' => !isset($json['ResultBBox']) ? null : $this->populateResultBoundingBox($json['ResultBBox']), - 'Text' => (string) $json['Text'], + 'DataSource' => (string) $json['DataSource'], + 'Language' => isset($json['Language']) ? (string) $json['Language'] : null, + 'FilterCategories' => !isset($json['FilterCategories']) ? null : $this->populateResultFilterPlaceCategoryList($json['FilterCategories']), ]); } diff --git a/src/ValueObject/CalculateRouteMatrixSummary.php b/src/ValueObject/CalculateRouteMatrixSummary.php index 31a783d..4da1492 100644 --- a/src/ValueObject/CalculateRouteMatrixSummary.php +++ b/src/ValueObject/CalculateRouteMatrixSummary.php @@ -27,11 +27,12 @@ final class CalculateRouteMatrixSummary private $dataSource; /** - * The unit of measurement for route distances. + * The count of cells in the route matrix. Equal to the number of `DeparturePositions` multiplied by the number of + * `DestinationPositions`. * - * @var DistanceUnit::* + * @var int */ - private $distanceUnit; + private $routeCount; /** * The count of error results in the route matrix. If this number is 0, all routes were calculated successfully. @@ -41,35 +42,34 @@ final class CalculateRouteMatrixSummary private $errorCount; /** - * The count of cells in the route matrix. Equal to the number of `DeparturePositions` multiplied by the number of - * `DestinationPositions`. + * The unit of measurement for route distances. * - * @var int + * @var DistanceUnit::* */ - private $routeCount; + private $distanceUnit; /** * @param array{ * DataSource: string, - * DistanceUnit: DistanceUnit::*, - * ErrorCount: int, * RouteCount: int, + * ErrorCount: int, + * DistanceUnit: DistanceUnit::*, * } $input */ public function __construct(array $input) { $this->dataSource = $input['DataSource'] ?? $this->throwException(new InvalidArgument('Missing required field "DataSource".')); - $this->distanceUnit = $input['DistanceUnit'] ?? $this->throwException(new InvalidArgument('Missing required field "DistanceUnit".')); - $this->errorCount = $input['ErrorCount'] ?? $this->throwException(new InvalidArgument('Missing required field "ErrorCount".')); $this->routeCount = $input['RouteCount'] ?? $this->throwException(new InvalidArgument('Missing required field "RouteCount".')); + $this->errorCount = $input['ErrorCount'] ?? $this->throwException(new InvalidArgument('Missing required field "ErrorCount".')); + $this->distanceUnit = $input['DistanceUnit'] ?? $this->throwException(new InvalidArgument('Missing required field "DistanceUnit".')); } /** * @param array{ * DataSource: string, - * DistanceUnit: DistanceUnit::*, - * ErrorCount: int, * RouteCount: int, + * ErrorCount: int, + * DistanceUnit: DistanceUnit::*, * }|CalculateRouteMatrixSummary $input */ public static function create($input): self diff --git a/src/ValueObject/CalculateRouteSummary.php b/src/ValueObject/CalculateRouteSummary.php index 6166272..29fee9e 100644 --- a/src/ValueObject/CalculateRouteSummary.php +++ b/src/ValueObject/CalculateRouteSummary.php @@ -10,6 +10,24 @@ */ final class CalculateRouteSummary { + /** + * Specifies a geographical box surrounding a route. Used to zoom into a route when displaying it in a map. For example, + * `[min x, min y, max x, max y]`. + * + * The first 2 `bbox` parameters describe the lower southwest corner: + * + * - The first `bbox` position is the X coordinate or longitude of the lower southwest corner. + * - The second `bbox` position is the Y coordinate or latitude of the lower southwest corner. + * + * The next 2 `bbox` parameters describe the upper northeast corner: + * + * - The third `bbox` position is the X coordinate, or longitude of the upper northeast corner. + * - The fourth `bbox` position is the Y coordinate, or latitude of the upper northeast corner. + * + * @var float[] + */ + private $routeBbox; + /** * The data provider of traffic and road network data used to calculate the route. Indicates one of the available * providers: @@ -36,13 +54,6 @@ final class CalculateRouteSummary */ private $distance; - /** - * The unit of measurement for route distances. - * - * @var DistanceUnit::* - */ - private $distanceUnit; - /** * The total travel time for the route measured in seconds. The sum of the travel time between every stop on the route. * @@ -51,48 +62,37 @@ final class CalculateRouteSummary private $durationSeconds; /** - * Specifies a geographical box surrounding a route. Used to zoom into a route when displaying it in a map. For example, - * `[min x, min y, max x, max y]`. - * - * The first 2 `bbox` parameters describe the lower southwest corner: - * - * - The first `bbox` position is the X coordinate or longitude of the lower southwest corner. - * - The second `bbox` position is the Y coordinate or latitude of the lower southwest corner. - * - * The next 2 `bbox` parameters describe the upper northeast corner: - * - * - The third `bbox` position is the X coordinate, or longitude of the upper northeast corner. - * - The fourth `bbox` position is the Y coordinate, or latitude of the upper northeast corner. + * The unit of measurement for route distances. * - * @var float[] + * @var DistanceUnit::* */ - private $routeBbox; + private $distanceUnit; /** * @param array{ + * RouteBBox: float[], * DataSource: string, * Distance: float, - * DistanceUnit: DistanceUnit::*, * DurationSeconds: float, - * RouteBBox: float[], + * DistanceUnit: DistanceUnit::*, * } $input */ public function __construct(array $input) { + $this->routeBbox = $input['RouteBBox'] ?? $this->throwException(new InvalidArgument('Missing required field "RouteBBox".')); $this->dataSource = $input['DataSource'] ?? $this->throwException(new InvalidArgument('Missing required field "DataSource".')); $this->distance = $input['Distance'] ?? $this->throwException(new InvalidArgument('Missing required field "Distance".')); - $this->distanceUnit = $input['DistanceUnit'] ?? $this->throwException(new InvalidArgument('Missing required field "DistanceUnit".')); $this->durationSeconds = $input['DurationSeconds'] ?? $this->throwException(new InvalidArgument('Missing required field "DurationSeconds".')); - $this->routeBbox = $input['RouteBBox'] ?? $this->throwException(new InvalidArgument('Missing required field "RouteBBox".')); + $this->distanceUnit = $input['DistanceUnit'] ?? $this->throwException(new InvalidArgument('Missing required field "DistanceUnit".')); } /** * @param array{ + * RouteBBox: float[], * DataSource: string, * Distance: float, - * DistanceUnit: DistanceUnit::*, * DurationSeconds: float, - * RouteBBox: float[], + * DistanceUnit: DistanceUnit::*, * }|CalculateRouteSummary $input */ public static function create($input): self diff --git a/src/ValueObject/Leg.php b/src/ValueObject/Leg.php index 8eaf67b..5deda12 100644 --- a/src/ValueObject/Leg.php +++ b/src/ValueObject/Leg.php @@ -25,21 +25,15 @@ final class Leg { /** - * The distance between the leg's `StartPosition` and `EndPosition` along a calculated route. + * The starting position of the leg. Follows the format `[longitude,latitude]`. * - * - The default measurement is `Kilometers` unless the request specifies a `DistanceUnit` of `Miles`. + * > If the `StartPosition` isn't located on a road, it's snapped to a nearby road [^1]. * - * @var float - */ - private $distance; - - /** - * The estimated travel time between the leg's `StartPosition` and `EndPosition`. The travel mode and departure time - * that you specify in the request determines the calculated time. + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/snap-to-nearby-road.html * - * @var float + * @var float[] */ - private $durationSeconds; + private $startPosition; /** * The terminating position of the leg. Follows the format `[longitude,latitude]`. @@ -53,22 +47,28 @@ final class Leg private $endPosition; /** - * Contains the calculated route's path as a linestring geometry. + * The distance between the leg's `StartPosition` and `EndPosition` along a calculated route. * - * @var LegGeometry|null + * - The default measurement is `Kilometers` unless the request specifies a `DistanceUnit` of `Miles`. + * + * @var float */ - private $geometry; + private $distance; /** - * The starting position of the leg. Follows the format `[longitude,latitude]`. - * - * > If the `StartPosition` isn't located on a road, it's snapped to a nearby road [^1]. + * The estimated travel time between the leg's `StartPosition` and `EndPosition`. The travel mode and departure time + * that you specify in the request determines the calculated time. * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/snap-to-nearby-road.html + * @var float + */ + private $durationSeconds; + + /** + * Contains the calculated route's path as a linestring geometry. * - * @var float[] + * @var LegGeometry|null */ - private $startPosition; + private $geometry; /** * Contains a list of steps, which represent subsections of a leg. Each step provides instructions for how to move to @@ -81,31 +81,31 @@ final class Leg /** * @param array{ + * StartPosition: float[], + * EndPosition: float[], * Distance: float, * DurationSeconds: float, - * EndPosition: float[], * Geometry?: null|LegGeometry|array, - * StartPosition: float[], * Steps: array, * } $input */ public function __construct(array $input) { + $this->startPosition = $input['StartPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "StartPosition".')); + $this->endPosition = $input['EndPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "EndPosition".')); $this->distance = $input['Distance'] ?? $this->throwException(new InvalidArgument('Missing required field "Distance".')); $this->durationSeconds = $input['DurationSeconds'] ?? $this->throwException(new InvalidArgument('Missing required field "DurationSeconds".')); - $this->endPosition = $input['EndPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "EndPosition".')); $this->geometry = isset($input['Geometry']) ? LegGeometry::create($input['Geometry']) : null; - $this->startPosition = $input['StartPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "StartPosition".')); $this->steps = isset($input['Steps']) ? array_map([Step::class, 'create'], $input['Steps']) : $this->throwException(new InvalidArgument('Missing required field "Steps".')); } /** * @param array{ + * StartPosition: float[], + * EndPosition: float[], * Distance: float, * DurationSeconds: float, - * EndPosition: float[], * Geometry?: null|LegGeometry|array, - * StartPosition: float[], * Steps: array, * }|Leg $input */ diff --git a/src/ValueObject/Place.php b/src/ValueObject/Place.php index b728f60..d760474 100644 --- a/src/ValueObject/Place.php +++ b/src/ValueObject/Place.php @@ -12,60 +12,38 @@ final class Place { /** - * The numerical portion of an address, such as a building number. + * The full name and address of the point of interest such as a city, region, or country. For example, `123 Any Street, + * Any Town, USA`. * * @var string|null */ - private $addressNumber; + private $label; /** - * The Amazon Location categories that describe this Place. - * - * For more information about using categories, including a list of Amazon Location categories, see Categories and - * filtering [^1], in the *Amazon Location Service Developer Guide*. - * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/category-filtering.html - * - * @var string[]|null + * @var PlaceGeometry */ - private $categories; + private $geometry; /** - * A country/region specified using ISO 3166 [^1] 3-digit country/region code. For example, `CAN`. - * - * [^1]: https://www.iso.org/iso-3166-country-codes.html + * The numerical portion of an address, such as a building number. * * @var string|null */ - private $country; - - /** - * @var PlaceGeometry - */ - private $geometry; + private $addressNumber; /** - * `True` if the result is interpolated from other known places. - * - * `False` if the Place is a known place. - * - * Not returned when the partner does not provide the information. - * - * For example, returns `False` for an address location that is found in the partner data, but returns `True` if an - * address does not exist in the partner data and its location is calculated by interpolating between other known - * addresses. + * The name for a street or a road to identify a location. For example, `Main Street`. * - * @var bool|null + * @var string|null */ - private $interpolated; + private $street; /** - * The full name and address of the point of interest such as a city, region, or country. For example, `123 Any Street, - * Any Town, USA`. + * The name of a community district. For example, `Downtown`. * * @var string|null */ - private $label; + private $neighborhood; /** * A name for a local area, such as a city or town name. For example, `Toronto`. @@ -75,75 +53,72 @@ final class Place private $municipality; /** - * The name of a community district. For example, `Downtown`. + * A county, or an area that's part of a larger region. For example, `Metro Vancouver`. * * @var string|null */ - private $neighborhood; + private $subRegion; /** - * A group of numbers and letters in a country-specific format, which accompanies the address for the purpose of - * identifying a location. + * A name for an area or geographical division, such as a province or state name. For example, `British Columbia`. * * @var string|null */ - private $postalCode; + private $region; /** - * A name for an area or geographical division, such as a province or state name. For example, `British Columbia`. + * A country/region specified using ISO 3166 [^1] 3-digit country/region code. For example, `CAN`. + * + * [^1]: https://www.iso.org/iso-3166-country-codes.html * * @var string|null */ - private $region; + private $country; /** - * The name for a street or a road to identify a location. For example, `Main Street`. + * A group of numbers and letters in a country-specific format, which accompanies the address for the purpose of + * identifying a location. * * @var string|null */ - private $street; + private $postalCode; /** - * An area that's part of a larger municipality. For example, `Blissville` is a submunicipality in the Queen County in - * New York. + * `True` if the result is interpolated from other known places. * - * > This property is only returned for a place index that uses Esri as a data provider. The property is represented as - * > a `district`. + * `False` if the Place is a known place. * - * For more information about data providers, see Amazon Location Service data providers [^1]. + * Not returned when the partner does not provide the information. * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/what-is-data-provider.html + * For example, returns `False` for an address location that is found in the partner data, but returns `True` if an + * address does not exist in the partner data and its location is calculated by interpolating between other known + * addresses. * - * @var string|null + * @var bool|null */ - private $subMunicipality; + private $interpolated; /** - * A county, or an area that's part of a larger region. For example, `Metro Vancouver`. + * The time zone in which the `Place` is located. Returned only when using HERE or Grab as the selected partner. * - * @var string|null + * @var TimeZone|null */ - private $subRegion; + private $timeZone; /** - * Categories from the data provider that describe the Place that are not mapped to any Amazon Location categories. + * For addresses with a `UnitNumber`, the type of unit. For example, `Apartment`. * - * @var string[]|null - */ - private $supplementalCategories; - - /** - * The time zone in which the `Place` is located. Returned only when using HERE or Grab as the selected partner. + * > Returned only for a place index that uses Esri as a data provider. * - * @var TimeZone|null + * @var string|null */ - private $timeZone; + private $unitType; /** * For addresses with multiple units, the unit identifier. Can include numbers and letters, for example `3B` or `Unit * 123`. * - * > This property is returned only for a place index that uses Esri or Grab as a data provider. It is not returned for + * > Returned only for a place index that uses Esri or Grab as a data provider. Is not returned for * > `SearchPlaceIndexForPosition`. * * @var string|null @@ -151,75 +126,96 @@ final class Place private $unitNumber; /** - * For addresses with a `UnitNumber`, the type of unit. For example, `Apartment`. + * The Amazon Location categories that describe this Place. + * + * For more information about using categories, including a list of Amazon Location categories, see Categories and + * filtering [^1], in the *Amazon Location Service Developer Guide*. + * + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/category-filtering.html + * + * @var string[]|null + */ + private $categories; + + /** + * Categories from the data provider that describe the Place that are not mapped to any Amazon Location categories. + * + * @var string[]|null + */ + private $supplementalCategories; + + /** + * An area that's part of a larger municipality. For example, `Blissville ` is a submunicipality in the Queen County in + * New York. * - * > This property is returned only for a place index that uses Esri as a data provider. + * > This property supported by Esri and OpenData. The Esri property is `district`, and the OpenData property is + * > `borough`. * * @var string|null */ - private $unitType; + private $subMunicipality; /** * @param array{ - * AddressNumber?: null|string, - * Categories?: null|string[], - * Country?: null|string, - * Geometry: PlaceGeometry|array, - * Interpolated?: null|bool, * Label?: null|string, - * Municipality?: null|string, - * Neighborhood?: null|string, - * PostalCode?: null|string, - * Region?: null|string, + * Geometry: PlaceGeometry|array, + * AddressNumber?: null|string, * Street?: null|string, - * SubMunicipality?: null|string, + * Neighborhood?: null|string, + * Municipality?: null|string, * SubRegion?: null|string, - * SupplementalCategories?: null|string[], + * Region?: null|string, + * Country?: null|string, + * PostalCode?: null|string, + * Interpolated?: null|bool, * TimeZone?: null|TimeZone|array, - * UnitNumber?: null|string, * UnitType?: null|string, + * UnitNumber?: null|string, + * Categories?: null|string[], + * SupplementalCategories?: null|string[], + * SubMunicipality?: null|string, * } $input */ public function __construct(array $input) { - $this->addressNumber = $input['AddressNumber'] ?? null; - $this->categories = $input['Categories'] ?? null; - $this->country = $input['Country'] ?? null; - $this->geometry = isset($input['Geometry']) ? PlaceGeometry::create($input['Geometry']) : $this->throwException(new InvalidArgument('Missing required field "Geometry".')); - $this->interpolated = $input['Interpolated'] ?? null; $this->label = $input['Label'] ?? null; - $this->municipality = $input['Municipality'] ?? null; - $this->neighborhood = $input['Neighborhood'] ?? null; - $this->postalCode = $input['PostalCode'] ?? null; - $this->region = $input['Region'] ?? null; + $this->geometry = isset($input['Geometry']) ? PlaceGeometry::create($input['Geometry']) : $this->throwException(new InvalidArgument('Missing required field "Geometry".')); + $this->addressNumber = $input['AddressNumber'] ?? null; $this->street = $input['Street'] ?? null; - $this->subMunicipality = $input['SubMunicipality'] ?? null; + $this->neighborhood = $input['Neighborhood'] ?? null; + $this->municipality = $input['Municipality'] ?? null; $this->subRegion = $input['SubRegion'] ?? null; - $this->supplementalCategories = $input['SupplementalCategories'] ?? null; + $this->region = $input['Region'] ?? null; + $this->country = $input['Country'] ?? null; + $this->postalCode = $input['PostalCode'] ?? null; + $this->interpolated = $input['Interpolated'] ?? null; $this->timeZone = isset($input['TimeZone']) ? TimeZone::create($input['TimeZone']) : null; - $this->unitNumber = $input['UnitNumber'] ?? null; $this->unitType = $input['UnitType'] ?? null; + $this->unitNumber = $input['UnitNumber'] ?? null; + $this->categories = $input['Categories'] ?? null; + $this->supplementalCategories = $input['SupplementalCategories'] ?? null; + $this->subMunicipality = $input['SubMunicipality'] ?? null; } /** * @param array{ - * AddressNumber?: null|string, - * Categories?: null|string[], - * Country?: null|string, - * Geometry: PlaceGeometry|array, - * Interpolated?: null|bool, * Label?: null|string, - * Municipality?: null|string, - * Neighborhood?: null|string, - * PostalCode?: null|string, - * Region?: null|string, + * Geometry: PlaceGeometry|array, + * AddressNumber?: null|string, * Street?: null|string, - * SubMunicipality?: null|string, + * Neighborhood?: null|string, + * Municipality?: null|string, * SubRegion?: null|string, - * SupplementalCategories?: null|string[], + * Region?: null|string, + * Country?: null|string, + * PostalCode?: null|string, + * Interpolated?: null|bool, * TimeZone?: null|TimeZone|array, - * UnitNumber?: null|string, * UnitType?: null|string, + * UnitNumber?: null|string, + * Categories?: null|string[], + * SupplementalCategories?: null|string[], + * SubMunicipality?: null|string, * }|Place $input */ public static function create($input): self diff --git a/src/ValueObject/SearchForPositionResult.php b/src/ValueObject/SearchForPositionResult.php index 8d163a5..a736b2a 100644 --- a/src/ValueObject/SearchForPositionResult.php +++ b/src/ValueObject/SearchForPositionResult.php @@ -9,6 +9,13 @@ */ final class SearchForPositionResult { + /** + * Details about the search result, such as its address and position. + * + * @var Place + */ + private $place; + /** * The distance in meters of a great-circle arc between the query position and the result. * @@ -19,13 +26,6 @@ final class SearchForPositionResult */ private $distance; - /** - * Details about the search result, such as its address and position. - * - * @var Place - */ - private $place; - /** * The unique identifier of the place. You can use this with the `GetPlace` operation to find the place again later. * @@ -38,22 +38,22 @@ final class SearchForPositionResult /** * @param array{ - * Distance: float, * Place: Place|array, + * Distance: float, * PlaceId?: null|string, * } $input */ public function __construct(array $input) { - $this->distance = $input['Distance'] ?? $this->throwException(new InvalidArgument('Missing required field "Distance".')); $this->place = isset($input['Place']) ? Place::create($input['Place']) : $this->throwException(new InvalidArgument('Missing required field "Place".')); + $this->distance = $input['Distance'] ?? $this->throwException(new InvalidArgument('Missing required field "Distance".')); $this->placeId = $input['PlaceId'] ?? null; } /** * @param array{ - * Distance: float, * Place: Place|array, + * Distance: float, * PlaceId?: null|string, * }|SearchForPositionResult $input */ diff --git a/src/ValueObject/SearchForTextResult.php b/src/ValueObject/SearchForTextResult.php index 45a8a30..2859c4e 100644 --- a/src/ValueObject/SearchForTextResult.php +++ b/src/ValueObject/SearchForTextResult.php @@ -9,6 +9,13 @@ */ final class SearchForTextResult { + /** + * Details about the search result, such as its address and position. + * + * @var Place + */ + private $place; + /** * The distance in meters of a great-circle arc between the bias position specified and the result. `Distance` will be * returned only if a bias position was specified in the query. @@ -21,11 +28,15 @@ final class SearchForTextResult private $distance; /** - * Details about the search result, such as its address and position. + * The relative confidence in the match for a result among the results returned. For example, if more fields for an + * address match (including house number, street, city, country/region, and postal code), the relevance score is closer + * to 1. * - * @var Place + * Returned only when the partner selected is Esri or Grab. + * + * @var float|null */ - private $place; + private $relevance; /** * The unique identifier of the place. You can use this with the `GetPlace` operation to find the place again later. @@ -37,39 +48,28 @@ final class SearchForTextResult */ private $placeId; - /** - * The relative confidence in the match for a result among the results returned. For example, if more fields for an - * address match (including house number, street, city, country/region, and postal code), the relevance score is closer - * to 1. - * - * Returned only when the partner selected is Esri or Grab. - * - * @var float|null - */ - private $relevance; - /** * @param array{ - * Distance?: null|float, * Place: Place|array, - * PlaceId?: null|string, + * Distance?: null|float, * Relevance?: null|float, + * PlaceId?: null|string, * } $input */ public function __construct(array $input) { - $this->distance = $input['Distance'] ?? null; $this->place = isset($input['Place']) ? Place::create($input['Place']) : $this->throwException(new InvalidArgument('Missing required field "Place".')); - $this->placeId = $input['PlaceId'] ?? null; + $this->distance = $input['Distance'] ?? null; $this->relevance = $input['Relevance'] ?? null; + $this->placeId = $input['PlaceId'] ?? null; } /** * @param array{ - * Distance?: null|float, * Place: Place|array, - * PlaceId?: null|string, + * Distance?: null|float, * Relevance?: null|float, + * PlaceId?: null|string, * }|SearchForTextResult $input */ public static function create($input): self diff --git a/src/ValueObject/SearchPlaceIndexForPositionSummary.php b/src/ValueObject/SearchPlaceIndexForPositionSummary.php index 59ab50c..7855f08 100644 --- a/src/ValueObject/SearchPlaceIndexForPositionSummary.php +++ b/src/ValueObject/SearchPlaceIndexForPositionSummary.php @@ -9,6 +9,22 @@ */ final class SearchPlaceIndexForPositionSummary { + /** + * The position specified in the request. + * + * @var float[] + */ + private $position; + + /** + * Contains the optional result count limit that is specified in the request. + * + * Default value: `50` + * + * @var int|null + */ + private $maxResults; + /** * The geospatial data provider attached to the place index resource specified in the request. Values can be one of the * following: @@ -35,44 +51,28 @@ final class SearchPlaceIndexForPositionSummary */ private $language; - /** - * Contains the optional result count limit that is specified in the request. - * - * Default value: `50` - * - * @var int|null - */ - private $maxResults; - - /** - * The position specified in the request. - * - * @var float[] - */ - private $position; - /** * @param array{ + * Position: float[], + * MaxResults?: null|int, * DataSource: string, * Language?: null|string, - * MaxResults?: null|int, - * Position: float[], * } $input */ public function __construct(array $input) { + $this->position = $input['Position'] ?? $this->throwException(new InvalidArgument('Missing required field "Position".')); + $this->maxResults = $input['MaxResults'] ?? null; $this->dataSource = $input['DataSource'] ?? $this->throwException(new InvalidArgument('Missing required field "DataSource".')); $this->language = $input['Language'] ?? null; - $this->maxResults = $input['MaxResults'] ?? null; - $this->position = $input['Position'] ?? $this->throwException(new InvalidArgument('Missing required field "Position".')); } /** * @param array{ + * Position: float[], + * MaxResults?: null|int, * DataSource: string, * Language?: null|string, - * MaxResults?: null|int, - * Position: float[], * }|SearchPlaceIndexForPositionSummary $input */ public static function create($input): self diff --git a/src/ValueObject/SearchPlaceIndexForTextSummary.php b/src/ValueObject/SearchPlaceIndexForTextSummary.php index 8363bf2..6724b22 100644 --- a/src/ValueObject/SearchPlaceIndexForTextSummary.php +++ b/src/ValueObject/SearchPlaceIndexForTextSummary.php @@ -9,6 +9,13 @@ */ final class SearchPlaceIndexForTextSummary { + /** + * The search text specified in the request. + * + * @var string + */ + private $text; + /** * Contains the coordinates for the optional bias position specified in the request. * @@ -21,22 +28,6 @@ final class SearchPlaceIndexForTextSummary */ private $biasPosition; - /** - * The geospatial data provider attached to the place index resource specified in the request. Values can be one of the - * following: - * - * - Esri - * - Grab - * - Here - * - * For more information about data providers, see Amazon Location Service data providers [^1]. - * - * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/what-is-data-provider.html - * - * @var string - */ - private $dataSource; - /** * Contains the coordinates for the optional bounding box specified in the request. * @@ -44,13 +35,6 @@ final class SearchPlaceIndexForTextSummary */ private $filterBbox; - /** - * The optional category filter specified in the request. - * - * @var string[]|null - */ - private $filterCategories; - /** * Contains the optional country filter specified in the request. * @@ -58,16 +42,6 @@ final class SearchPlaceIndexForTextSummary */ private $filterCountries; - /** - * The preferred language used to return results. Matches the language in the request. The value is a valid BCP 47 [^1] - * language tag, for example, `en` for English. - * - * [^1]: https://tools.ietf.org/search/bcp47 - * - * @var string|null - */ - private $language; - /** * Contains the optional result count limit specified in the request. * @@ -85,49 +59,75 @@ final class SearchPlaceIndexForTextSummary private $resultBbox; /** - * The search text specified in the request. + * The geospatial data provider attached to the place index resource specified in the request. Values can be one of the + * following: + * + * - Esri + * - Grab + * - Here + * + * For more information about data providers, see Amazon Location Service data providers [^1]. + * + * [^1]: https://docs.aws.amazon.com/location/latest/developerguide/what-is-data-provider.html * * @var string */ - private $text; + private $dataSource; + + /** + * The preferred language used to return results. Matches the language in the request. The value is a valid BCP 47 [^1] + * language tag, for example, `en` for English. + * + * [^1]: https://tools.ietf.org/search/bcp47 + * + * @var string|null + */ + private $language; + + /** + * The optional category filter specified in the request. + * + * @var string[]|null + */ + private $filterCategories; /** * @param array{ + * Text: string, * BiasPosition?: null|float[], - * DataSource: string, * FilterBBox?: null|float[], - * FilterCategories?: null|string[], * FilterCountries?: null|string[], - * Language?: null|string, * MaxResults?: null|int, * ResultBBox?: null|float[], - * Text: string, + * DataSource: string, + * Language?: null|string, + * FilterCategories?: null|string[], * } $input */ public function __construct(array $input) { + $this->text = $input['Text'] ?? $this->throwException(new InvalidArgument('Missing required field "Text".')); $this->biasPosition = $input['BiasPosition'] ?? null; - $this->dataSource = $input['DataSource'] ?? $this->throwException(new InvalidArgument('Missing required field "DataSource".')); $this->filterBbox = $input['FilterBBox'] ?? null; - $this->filterCategories = $input['FilterCategories'] ?? null; $this->filterCountries = $input['FilterCountries'] ?? null; - $this->language = $input['Language'] ?? null; $this->maxResults = $input['MaxResults'] ?? null; $this->resultBbox = $input['ResultBBox'] ?? null; - $this->text = $input['Text'] ?? $this->throwException(new InvalidArgument('Missing required field "Text".')); + $this->dataSource = $input['DataSource'] ?? $this->throwException(new InvalidArgument('Missing required field "DataSource".')); + $this->language = $input['Language'] ?? null; + $this->filterCategories = $input['FilterCategories'] ?? null; } /** * @param array{ + * Text: string, * BiasPosition?: null|float[], - * DataSource: string, * FilterBBox?: null|float[], - * FilterCategories?: null|string[], * FilterCountries?: null|string[], - * Language?: null|string, * MaxResults?: null|int, * ResultBBox?: null|float[], - * Text: string, + * DataSource: string, + * Language?: null|string, + * FilterCategories?: null|string[], * }|SearchPlaceIndexForTextSummary $input */ public static function create($input): self diff --git a/src/ValueObject/Step.php b/src/ValueObject/Step.php index 1f40c2c..1fbe2fd 100644 --- a/src/ValueObject/Step.php +++ b/src/ValueObject/Step.php @@ -10,6 +10,22 @@ */ final class Step { + /** + * The starting position of a step. If the position is the first step in the leg, this position is the same as the start + * position of the leg. + * + * @var float[] + */ + private $startPosition; + + /** + * The end position of a step. If the position the last step in the leg, this position is the same as the end position + * of the leg. + * + * @var float[] + */ + private $endPosition; + /** * The travel distance between the step's `StartPosition` and `EndPosition`. * @@ -25,14 +41,6 @@ final class Step */ private $durationSeconds; - /** - * The end position of a step. If the position the last step in the leg, this position is the same as the end position - * of the leg. - * - * @var float[] - */ - private $endPosition; - /** * Represents the start position, or index, in a sequence of steps within the leg's line string geometry. For example, * the index of the first step in a leg geometry is `0`. @@ -43,39 +51,31 @@ final class Step */ private $geometryOffset; - /** - * The starting position of a step. If the position is the first step in the leg, this position is the same as the start - * position of the leg. - * - * @var float[] - */ - private $startPosition; - /** * @param array{ + * StartPosition: float[], + * EndPosition: float[], * Distance: float, * DurationSeconds: float, - * EndPosition: float[], * GeometryOffset?: null|int, - * StartPosition: float[], * } $input */ public function __construct(array $input) { + $this->startPosition = $input['StartPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "StartPosition".')); + $this->endPosition = $input['EndPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "EndPosition".')); $this->distance = $input['Distance'] ?? $this->throwException(new InvalidArgument('Missing required field "Distance".')); $this->durationSeconds = $input['DurationSeconds'] ?? $this->throwException(new InvalidArgument('Missing required field "DurationSeconds".')); - $this->endPosition = $input['EndPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "EndPosition".')); $this->geometryOffset = $input['GeometryOffset'] ?? null; - $this->startPosition = $input['StartPosition'] ?? $this->throwException(new InvalidArgument('Missing required field "StartPosition".')); } /** * @param array{ + * StartPosition: float[], + * EndPosition: float[], * Distance: float, * DurationSeconds: float, - * EndPosition: float[], * GeometryOffset?: null|int, - * StartPosition: float[], * }|Step $input */ public static function create($input): self diff --git a/src/ValueObject/TruckDimensions.php b/src/ValueObject/TruckDimensions.php index 9448091..e303b50 100644 --- a/src/ValueObject/TruckDimensions.php +++ b/src/ValueObject/TruckDimensions.php @@ -11,17 +11,6 @@ */ final class TruckDimensions { - /** - * The height of the truck. - * - * - For example, `4.5`. - * - * > For routes calculated with a HERE resource, this value must be between 0 and 50 meters. - * - * @var float|null - */ - private $height; - /** * The length of the truck. * @@ -34,13 +23,15 @@ final class TruckDimensions private $length; /** - * Specifies the unit of measurement for the truck dimensions. + * The height of the truck. * - * Default Value: `Meters` + * - For example, `4.5`. * - * @var DimensionUnit::*|null + * > For routes calculated with a HERE resource, this value must be between 0 and 50 meters. + * + * @var float|null */ - private $unit; + private $height; /** * The width of the truck. @@ -53,28 +44,37 @@ final class TruckDimensions */ private $width; + /** + * Specifies the unit of measurement for the truck dimensions. + * + * Default Value: `Meters` + * + * @var DimensionUnit::*|null + */ + private $unit; + /** * @param array{ - * Height?: null|float, * Length?: null|float, - * Unit?: null|DimensionUnit::*, + * Height?: null|float, * Width?: null|float, + * Unit?: null|DimensionUnit::*, * } $input */ public function __construct(array $input) { - $this->height = $input['Height'] ?? null; $this->length = $input['Length'] ?? null; - $this->unit = $input['Unit'] ?? null; + $this->height = $input['Height'] ?? null; $this->width = $input['Width'] ?? null; + $this->unit = $input['Unit'] ?? null; } /** * @param array{ - * Height?: null|float, * Length?: null|float, - * Unit?: null|DimensionUnit::*, + * Height?: null|float, * Width?: null|float, + * Unit?: null|DimensionUnit::*, * }|TruckDimensions $input */ public static function create($input): self @@ -111,11 +111,14 @@ public function getWidth(): ?float public function requestBody(): array { $payload = []; + if (null !== $v = $this->length) { + $payload['Length'] = $v; + } if (null !== $v = $this->height) { $payload['Height'] = $v; } - if (null !== $v = $this->length) { - $payload['Length'] = $v; + if (null !== $v = $this->width) { + $payload['Width'] = $v; } if (null !== $v = $this->unit) { if (!DimensionUnit::exists($v)) { @@ -123,9 +126,6 @@ public function requestBody(): array } $payload['Unit'] = $v; } - if (null !== $v = $this->width) { - $payload['Width'] = $v; - } return $payload; } diff --git a/src/ValueObject/ValidationExceptionField.php b/src/ValueObject/ValidationExceptionField.php index 83ef0bb..1ff1a1d 100644 --- a/src/ValueObject/ValidationExceptionField.php +++ b/src/ValueObject/ValidationExceptionField.php @@ -10,35 +10,35 @@ final class ValidationExceptionField { /** - * A message with the reason for the validation exception error. + * The field name where the invalid entry was detected. * * @var string */ - private $message; + private $name; /** - * The field name where the invalid entry was detected. + * A message with the reason for the validation exception error. * * @var string */ - private $name; + private $message; /** * @param array{ - * Message: string, * Name: string, + * Message: string, * } $input */ public function __construct(array $input) { - $this->message = $input['Message'] ?? $this->throwException(new InvalidArgument('Missing required field "Message".')); $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->message = $input['Message'] ?? $this->throwException(new InvalidArgument('Missing required field "Message".')); } /** * @param array{ - * Message: string, * Name: string, + * Message: string, * }|ValidationExceptionField $input */ public static function create($input): self