Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
namespace Aws;
3
 
4
use Aws\Api\Service;
5
 
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
 
17
        return new ResultPaginator($this, $name, $args, $config);
18
    }
19
 
20
    public function getIterator($name, array $args = [])
21
    {
22
        $config = $this->getApi()->getPaginatorConfig($name);
23
        if (!$config['result_key']) {
24
            throw new \UnexpectedValueException(sprintf(
25
                'There are no resources to iterate for the %s operation of %s',
26
                $name, $this->getApi()['serviceFullName']
27
            ));
28
        }
29
 
30
        $key = is_array($config['result_key'])
31
            ? $config['result_key'][0]
32
            : $config['result_key'];
33
 
34
        if ($config['output_token'] && $config['input_token']) {
35
            return $this->getPaginator($name, $args)->search($key);
36
        }
37
 
38
        $result = $this->execute($this->getCommand($name, $args))->search($key);
39
 
40
        return new \ArrayIterator((array) $result);
41
    }
42
 
43
    public function waitUntil($name, array $args = [])
44
    {
45
        return $this->getWaiter($name, $args)->promise()->wait();
46
    }
47
 
48
    public function getWaiter($name, array $args = [])
49
    {
50
        $config = isset($args['@waiter']) ? $args['@waiter'] : [];
51
        $config += $this->getApi()->getWaiterConfig($name);
52
 
53
        return new Waiter($this, $name, $args, $config);
54
    }
55
 
56
    public function execute(CommandInterface $command)
57
    {
58
        return $this->executeAsync($command)->wait();
59
    }
60
 
61
    public function executeAsync(CommandInterface $command)
62
    {
63
        $handler = $command->getHandlerList()->resolve();
64
        return $handler($command);
65
    }
66
 
67
    public function __call($name, array $args)
68
    {
69
        if (substr($name, -5) === 'Async') {
70
            $name = substr($name, 0, -5);
71
            $isAsync = true;
72
        }
73
 
74
        if (!empty($this->aliases[ucfirst($name)])) {
75
            $name = $this->aliases[ucfirst($name)];
76
        }
77
 
78
        $params = isset($args[0]) ? $args[0] : [];
79
 
80
        if (!empty($isAsync)) {
81
            return $this->executeAsync(
82
                $this->getCommand($name, $params)
83
            );
84
        }
85
 
86
        return $this->execute($this->getCommand($name, $params));
87
    }
88
 
89
    /**
90
     * @param string $name
91
     * @param array $args
92
     *
93
     * @return CommandInterface
94
     */
95
    abstract public function getCommand($name, array $args = []);
96
 
97
    /**
98
     * @return Service
99
     */
100
    abstract public function getApi();
101
}