123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace AsyncAws\Core;
- use AsyncAws\Core\Exception\InvalidArgument;
- /**
- * Contains contextual information alongside a request.
- *
- * @author Jérémy Derussé <jeremy@derusse.com>
- *
- * @internal
- */
- class RequestContext
- {
- public const AVAILABLE_OPTIONS = [
- 'region' => true,
- 'operation' => true,
- 'expirationDate' => true,
- 'currentDate' => true,
- 'exceptionMapping' => true,
- 'usesEndpointDiscovery' => true,
- 'requiresEndpointDiscovery' => true,
- ];
- /**
- * @var string|null
- */
- private $operation;
- /**
- * @var bool
- */
- private $usesEndpointDiscovery = false;
- /**
- * @var bool
- */
- private $requiresEndpointDiscovery = false;
- /**
- * @var string|null
- */
- private $region;
- /**
- * @var \DateTimeImmutable|null
- */
- private $expirationDate;
- /**
- * @var \DateTimeImmutable|null
- */
- private $currentDate;
- /**
- * @var array<string, string>
- */
- private $exceptionMapping = [];
- /**
- * @param array{
- * operation?: null|string
- * region?: null|string
- * expirationDate?: null|\DateTimeImmutable
- * currentDate?: null|\DateTimeImmutable
- * exceptionMapping?: string[]
- * usesEndpointDiscovery?: bool
- * requiresEndpointDiscovery?: bool
- * }
- */
- public function __construct(array $options = [])
- {
- if (0 < \count($invalidOptions = array_diff_key($options, self::AVAILABLE_OPTIONS))) {
- throw new InvalidArgument(sprintf('Invalid option(s) "%s" passed to "%s". ', implode('", "', array_keys($invalidOptions)), __METHOD__));
- }
- foreach ($options as $property => $value) {
- $this->$property = $value;
- }
- }
- public function getOperation(): ?string
- {
- return $this->operation;
- }
- public function getRegion(): ?string
- {
- return $this->region;
- }
- public function getExpirationDate(): ?\DateTimeImmutable
- {
- return $this->expirationDate;
- }
- public function getCurrentDate(): ?\DateTimeImmutable
- {
- return $this->currentDate;
- }
- public function getExceptionMapping(): array
- {
- return $this->exceptionMapping;
- }
- public function usesEndpointDiscovery(): bool
- {
- return $this->usesEndpointDiscovery;
- }
- public function requiresEndpointDiscovery(): bool
- {
- return $this->requiresEndpointDiscovery;
- }
- }
|