vendor/aws/aws-sdk-php/src/AwsClientTrait.php line 86

Open in your IDE?
  1. <?php
  2. namespace Aws;
  3. use Aws\Api\Service;
  4. /**
  5.  * A trait providing generic functionality for interacting with Amazon Web
  6.  * Services. This is meant to be used in classes implementing
  7.  * \Aws\AwsClientInterface
  8.  */
  9. trait AwsClientTrait
  10. {
  11.     public function getPaginator($name, array $args = [])
  12.     {
  13.         $config $this->getApi()->getPaginatorConfig($name);
  14.         return new ResultPaginator($this$name$args$config);
  15.     }
  16.     public function getIterator($name, array $args = [])
  17.     {
  18.         $config $this->getApi()->getPaginatorConfig($name);
  19.         if (!$config['result_key']) {
  20.             throw new \UnexpectedValueException(sprintf(
  21.                 'There are no resources to iterate for the %s operation of %s',
  22.                 $name$this->getApi()['serviceFullName']
  23.             ));
  24.         }
  25.         $key is_array($config['result_key'])
  26.             ? $config['result_key'][0]
  27.             : $config['result_key'];
  28.         if ($config['output_token'] && $config['input_token']) {
  29.             return $this->getPaginator($name$args)->search($key);
  30.         }
  31.         $result $this->execute($this->getCommand($name$args))->search($key);
  32.         return new \ArrayIterator((array) $result);
  33.     }
  34.     public function waitUntil($name, array $args = [])
  35.     {
  36.         return $this->getWaiter($name$args)->promise()->wait();
  37.     }
  38.     public function getWaiter($name, array $args = [])
  39.     {
  40.         $config = isset($args['@waiter']) ? $args['@waiter'] : [];
  41.         $config += $this->getApi()->getWaiterConfig($name);
  42.         return new Waiter($this$name$args$config);
  43.     }
  44.     public function execute(CommandInterface $command)
  45.     {
  46.         return $this->executeAsync($command)->wait();
  47.     }
  48.     public function executeAsync(CommandInterface $command)
  49.     {
  50.         $handler $command->getHandlerList()->resolve();
  51.         return $handler($command);
  52.     }
  53.     public function __call($name, array $args)
  54.     {
  55.         if (substr($name, -5) === 'Async') {
  56.             $name substr($name0, -5);
  57.             $isAsync true;
  58.         }
  59.         if (!empty($this->aliases[ucfirst($name)])) {
  60.             $name $this->aliases[ucfirst($name)];
  61.         }
  62.         $params = isset($args[0]) ? $args[0] : [];
  63.         if (!empty($isAsync)) {
  64.             return $this->executeAsync(
  65.                 $this->getCommand($name$params)
  66.             );
  67.         }
  68.         return $this->execute($this->getCommand($name$params));
  69.     }
  70.     /**
  71.      * @param string $name
  72.      * @param array $args
  73.      *
  74.      * @return CommandInterface
  75.      */
  76.     abstract public function getCommand($name, array $args = []);
  77.     /**
  78.      * @return Service
  79.      */
  80.     abstract public function getApi();
  81. }