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
|
|
|
use function GuzzleHttp\Promise\promise_for; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @codeCoverageIgnore |
19
|
|
|
*/ |
20
|
|
|
class S3ClientStub implements S3ClientInterface |
21
|
|
|
{ |
22
|
|
|
use S3ClientTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var S3ClientInterface |
26
|
|
|
*/ |
27
|
|
|
private $actualClient; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var S3Exception[] |
31
|
|
|
*/ |
32
|
|
|
private $stagedExceptions = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ResultInterface[] |
36
|
|
|
*/ |
37
|
|
|
private $stagedResult = []; |
38
|
|
|
|
39
|
|
|
public function __construct(S3ClientInterface $client) |
40
|
|
|
{ |
41
|
|
|
return $this->actualClient = $client; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function failOnNextCopy(): void |
45
|
|
|
{ |
46
|
|
|
$this->throwExceptionWhenExecutingCommand('CopyObject'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function throwExceptionWhenExecutingCommand(string $commandName, S3Exception $exception = null): void |
50
|
|
|
{ |
51
|
|
|
$this->stagedExceptions[$commandName] = $exception ?: new S3Exception($commandName, new Command($commandName)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function throw500ExceptionWhenExecutingCommand(string $commandName): void |
55
|
|
|
{ |
56
|
|
|
$response = new Response(500); |
57
|
|
|
$exception = new S3Exception($commandName, new Command($commandName), compact('response')); |
58
|
|
|
|
59
|
|
|
$this->throwExceptionWhenExecutingCommand($commandName, $exception); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function stageResultForCommand(string $commandName, ResultInterface $result): void |
63
|
|
|
{ |
64
|
|
|
$this->stagedResult[$commandName] = $result; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function execute(CommandInterface $command) |
68
|
|
|
{ |
69
|
|
|
return $this->executeAsync($command)->wait(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getCommand($name, array $args = []) |
73
|
|
|
{ |
74
|
|
|
return $this->actualClient->getCommand($name, $args); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getHandlerList() |
78
|
|
|
{ |
79
|
|
|
return $this->actualClient->getHandlerList(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getIterator($name, array $args = []) |
83
|
|
|
{ |
84
|
|
|
return $this->actualClient->getIterator($name, $args); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function __call($name, array $arguments) |
88
|
|
|
{ |
89
|
|
|
return $this->actualClient->__call($name, $arguments); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function executeAsync(CommandInterface $command) |
93
|
|
|
{ |
94
|
|
|
$name = $command->getName(); |
95
|
|
|
|
96
|
|
|
if (array_key_exists($name, $this->stagedExceptions)) { |
97
|
|
|
$exception = $this->stagedExceptions[$name]; |
98
|
|
|
unset($this->stagedExceptions[$name]); |
99
|
|
|
throw $exception; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (array_key_exists($name, $this->stagedResult)) { |
103
|
|
|
$result = $this->stagedResult[$name]; |
104
|
|
|
unset($this->stagedResult[$name]); |
105
|
|
|
|
106
|
|
|
return promise_for($result); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $this->actualClient->executeAsync($command); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getCredentials() |
113
|
|
|
{ |
114
|
|
|
return $this->actualClient->getCredentials(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getRegion() |
118
|
|
|
{ |
119
|
|
|
return $this->actualClient->getRegion(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getEndpoint() |
123
|
|
|
{ |
124
|
|
|
return $this->actualClient->getEndpoint(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function getApi() |
128
|
|
|
{ |
129
|
|
|
return $this->actualClient->getApi(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getConfig($option = null) |
133
|
|
|
{ |
134
|
|
|
return $this->actualClient->getConfig($option); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getPaginator($name, array $args = []) |
138
|
|
|
{ |
139
|
|
|
return $this->actualClient->getPaginator($name, $args); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function waitUntil($name, array $args = []) |
143
|
|
|
{ |
144
|
|
|
$this->actualClient->waitUntil($name, $args); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getWaiter($name, array $args = []) |
148
|
|
|
{ |
149
|
|
|
return $this->actualClient->getWaiter($name, $args); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function createPresignedRequest(CommandInterface $command, $expires, array $options = []) |
153
|
|
|
{ |
154
|
|
|
return $this->actualClient->createPresignedRequest($command, $expires, $options); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getObjectUrl($bucket, $key) |
158
|
|
|
{ |
159
|
|
|
return $this->actualClient->getObjectUrl($bucket, $key); |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|