Completed
Push — 2.x ( 44f724...01e849 )
by Frank
04:30
created

S3ClientStub.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Flysystem\AwsS3V3;
6
7
use Aws\Command;
8
use Aws\CommandInterface;
9
use Aws\ResultInterface;
10
use Aws\S3\Exception\S3Exception;
11
use Aws\S3\S3ClientInterface;
12
use Aws\S3\S3ClientTrait;
13
use GuzzleHttp\Psr7\Response;
14
15
16
use function GuzzleHttp\Promise\promise_for;
17
18
/**
19
 * @codeCoverageIgnore
20
 */
21
class S3ClientStub implements S3ClientInterface
22
{
23
    use S3ClientTrait;
24
25
    /**
26
     * @var S3ClientInterface
27
     */
28
    private $actualClient;
29
30
    /**
31
     * @var S3Exception[]
32
     */
33
    private $stagedExceptions = [];
34
35
    /**
36
     * @var ResultInterface[]
37
     */
38
    private $stagedResult = [];
39
40
    public function __construct(S3ClientInterface $client)
41
    {
42
        return $this->actualClient = $client;
43
    }
44
45
    public function failOnNextCopy(): void
46
    {
47
        $this->throwExceptionWhenExecutingCommand('CopyObject');
48
    }
49
50
    public function throwExceptionWhenExecutingCommand(string $commandName, S3Exception $exception = null): void
51
    {
52
        $this->stagedExceptions[$commandName] = $exception ?: new S3Exception($commandName, new Command($commandName));
53
    }
54
55
    public function throw500ExceptionWhenExecutingCommand(string $commandName): void
56
    {
57
        $response = new Response(500);
58
        $exception = new S3Exception($commandName, new Command($commandName), compact('response'));
59
60
        $this->throwExceptionWhenExecutingCommand($commandName, $exception);
61
    }
62
63
    public function stageResultForCommand(string $commandName, ResultInterface $result): void
64
    {
65
        $this->stagedResult[$commandName] = $result;
66
    }
67
68
    public function execute(CommandInterface $command)
69
    {
70
        return $this->executeAsync($command)->wait();
71
    }
72
73
    public function getCommand($name, array $args = [])
74
    {
75
        return $this->actualClient->getCommand($name, $args);
76
    }
77
78
    public function getHandlerList()
79
    {
80
        return $this->actualClient->getHandlerList();
81
    }
82
83
    public function getIterator($name, array $args = [])
84
    {
85
        return $this->actualClient->getIterator($name, $args);
86
    }
87
88
    public function __call($name, array $arguments)
89
    {
90
        return $this->actualClient->__call($name, $arguments);
91
    }
92
93
    public function executeAsync(CommandInterface $command)
94
    {
95
        $name = $command->getName();
96
97
        if (array_key_exists($name, $this->stagedExceptions)) {
98
            $exception = $this->stagedExceptions[$name];
99
            unset($this->stagedExceptions[$name]);
100
            throw $exception;
101
        }
102
103
        if (array_key_exists($name, $this->stagedResult)) {
104
            $result = $this->stagedResult[$name];
105
            unset($this->stagedResult[$name]);
106
107
            return promise_for($result);
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Promise\promise_for() has been deprecated with message: promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
108
        }
109
110
        return $this->actualClient->executeAsync($command);
111
    }
112
113
    public function getCredentials()
114
    {
115
        return $this->actualClient->getCredentials();
116
    }
117
118
    public function getRegion()
119
    {
120
        return $this->actualClient->getRegion();
121
    }
122
123
    public function getEndpoint()
124
    {
125
        return $this->actualClient->getEndpoint();
126
    }
127
128
    public function getApi()
129
    {
130
        return $this->actualClient->getApi();
131
    }
132
133
    public function getConfig($option = null)
134
    {
135
        return $this->actualClient->getConfig($option);
136
    }
137
138
    public function getPaginator($name, array $args = [])
139
    {
140
        return $this->actualClient->getPaginator($name, $args);
141
    }
142
143
    public function waitUntil($name, array $args = [])
144
    {
145
        $this->actualClient->waitUntil($name, $args);
146
    }
147
148
    public function getWaiter($name, array $args = [])
149
    {
150
        return $this->actualClient->getWaiter($name, $args);
151
    }
152
153
    public function createPresignedRequest(CommandInterface $command, $expires, array $options = [])
154
    {
155
        return $this->actualClient->createPresignedRequest($command, $expires, $options);
156
    }
157
158
    public function getObjectUrl($bucket, $key)
159
    {
160
        return $this->actualClient->getObjectUrl($bucket, $key);
161
    }
162
}
163