1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace diecoding\aws\s3\commands; |
4
|
|
|
|
5
|
|
|
use Aws\ResultInterface; |
6
|
|
|
use diecoding\aws\s3\base\commands\ExecutableCommand; |
7
|
|
|
use diecoding\aws\s3\base\commands\traits\Async; |
8
|
|
|
use diecoding\aws\s3\base\commands\traits\Options; |
9
|
|
|
use diecoding\aws\s3\interfaces\commands\Asynchronous; |
10
|
|
|
use diecoding\aws\s3\interfaces\commands\HasBucket; |
11
|
|
|
use diecoding\aws\s3\interfaces\commands\PlainCommand; |
12
|
|
|
use GuzzleHttp\Promise\PromiseInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class GetCommand |
16
|
|
|
* |
17
|
|
|
* @method ResultInterface|PromiseInterface execute() |
18
|
|
|
* |
19
|
|
|
* @package diecoding\aws\s3\commands |
20
|
|
|
*/ |
21
|
|
|
class GetCommand extends ExecutableCommand implements PlainCommand, HasBucket, Asynchronous |
22
|
|
|
{ |
23
|
|
|
use Async; |
24
|
|
|
use Options; |
25
|
|
|
|
26
|
|
|
/** @var array */ |
27
|
|
|
protected $args = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function getBucket(): string |
33
|
|
|
{ |
34
|
|
|
return $this->args['Bucket'] ?? ''; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $name |
39
|
|
|
* |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
|
|
public function inBucket(string $name) |
43
|
|
|
{ |
44
|
|
|
$this->args['Bucket'] = $name; |
45
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getFilename(): string |
53
|
|
|
{ |
54
|
|
|
return $this->args['Key'] ?? ''; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $filename |
59
|
|
|
* |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function byFilename(string $filename) |
63
|
|
|
{ |
64
|
|
|
$this->args['Key'] = $filename; |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $value |
71
|
|
|
* |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function saveAs(string $value) |
75
|
|
|
{ |
76
|
|
|
$this->args['SaveAs'] = $value; |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $ifMatch |
83
|
|
|
* |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function ifMatch(string $ifMatch) |
87
|
|
|
{ |
88
|
|
|
$this->args['IfMatch'] = $ifMatch; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @internal used by the handlers |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getName(): string |
99
|
|
|
{ |
100
|
|
|
return 'GetObject'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @internal used by the handlers |
105
|
|
|
* |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function toArgs(): array |
109
|
|
|
{ |
110
|
|
|
return array_replace($this->options, $this->args); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|