PluginProbe
Media Cloud Sync / 1.2.12
Media Cloud Sync v1.2.12
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / sdk / s3 / Aws / AwsClientTrait.php

AwsClientTrait.php in Media Cloud Sync 1.2.12, at includes/sdk/s3/Aws/AwsClientTrait.php

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