RequestContext.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace AsyncAws\Core;
  3. use AsyncAws\Core\Exception\InvalidArgument;
  4. /**
  5. * Contains contextual information alongside a request.
  6. *
  7. * @author Jérémy Derussé <jeremy@derusse.com>
  8. *
  9. * @internal
  10. */
  11. class RequestContext
  12. {
  13. public const AVAILABLE_OPTIONS = [
  14. 'region' => true,
  15. 'operation' => true,
  16. 'expirationDate' => true,
  17. 'currentDate' => true,
  18. 'exceptionMapping' => true,
  19. 'usesEndpointDiscovery' => true,
  20. 'requiresEndpointDiscovery' => true,
  21. ];
  22. /**
  23. * @var string|null
  24. */
  25. private $operation;
  26. /**
  27. * @var bool
  28. */
  29. private $usesEndpointDiscovery = false;
  30. /**
  31. * @var bool
  32. */
  33. private $requiresEndpointDiscovery = false;
  34. /**
  35. * @var string|null
  36. */
  37. private $region;
  38. /**
  39. * @var \DateTimeImmutable|null
  40. */
  41. private $expirationDate;
  42. /**
  43. * @var \DateTimeImmutable|null
  44. */
  45. private $currentDate;
  46. /**
  47. * @var array<string, string>
  48. */
  49. private $exceptionMapping = [];
  50. /**
  51. * @param array{
  52. * operation?: null|string
  53. * region?: null|string
  54. * expirationDate?: null|\DateTimeImmutable
  55. * currentDate?: null|\DateTimeImmutable
  56. * exceptionMapping?: string[]
  57. * usesEndpointDiscovery?: bool
  58. * requiresEndpointDiscovery?: bool
  59. * }
  60. */
  61. public function __construct(array $options = [])
  62. {
  63. if (0 < \count($invalidOptions = array_diff_key($options, self::AVAILABLE_OPTIONS))) {
  64. throw new InvalidArgument(sprintf('Invalid option(s) "%s" passed to "%s". ', implode('", "', array_keys($invalidOptions)), __METHOD__));
  65. }
  66. foreach ($options as $property => $value) {
  67. $this->$property = $value;
  68. }
  69. }
  70. public function getOperation(): ?string
  71. {
  72. return $this->operation;
  73. }
  74. public function getRegion(): ?string
  75. {
  76. return $this->region;
  77. }
  78. public function getExpirationDate(): ?\DateTimeImmutable
  79. {
  80. return $this->expirationDate;
  81. }
  82. public function getCurrentDate(): ?\DateTimeImmutable
  83. {
  84. return $this->currentDate;
  85. }
  86. public function getExceptionMapping(): array
  87. {
  88. return $this->exceptionMapping;
  89. }
  90. public function usesEndpointDiscovery(): bool
  91. {
  92. return $this->usesEndpointDiscovery;
  93. }
  94. public function requiresEndpointDiscovery(): bool
  95. {
  96. return $this->requiresEndpointDiscovery;
  97. }
  98. }