ObjectExistsWaiter.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace AsyncAws\S3\Result;
  3. use AsyncAws\Core\Exception\Http\HttpException;
  4. use AsyncAws\Core\Exception\InvalidArgument;
  5. use AsyncAws\Core\Response;
  6. use AsyncAws\Core\Waiter;
  7. use AsyncAws\S3\Input\HeadObjectRequest;
  8. use AsyncAws\S3\S3Client;
  9. class ObjectExistsWaiter extends Waiter
  10. {
  11. protected const WAIT_TIMEOUT = 100.0;
  12. protected const WAIT_DELAY = 5.0;
  13. protected function extractState(Response $response, ?HttpException $exception): string
  14. {
  15. if (200 === $response->getStatusCode()) {
  16. return self::STATE_SUCCESS;
  17. }
  18. if (404 === $response->getStatusCode()) {
  19. return self::STATE_PENDING;
  20. }
  21. return null === $exception ? self::STATE_PENDING : self::STATE_FAILURE;
  22. }
  23. protected function refreshState(): Waiter
  24. {
  25. if (!$this->awsClient instanceof S3Client) {
  26. throw new InvalidArgument('missing client injected in waiter result');
  27. }
  28. if (!$this->input instanceof HeadObjectRequest) {
  29. throw new InvalidArgument('missing last request injected in waiter result');
  30. }
  31. return $this->awsClient->objectExists($this->input);
  32. }
  33. }