|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace diecoding\aws\s3; |
|
4
|
|
|
|
|
5
|
|
|
use diecoding\aws\s3\commands\DeleteCommand; |
|
6
|
|
|
use diecoding\aws\s3\commands\ExistCommand; |
|
7
|
|
|
use diecoding\aws\s3\commands\GetCommand; |
|
8
|
|
|
use diecoding\aws\s3\commands\GetPresignedUrlCommand; |
|
9
|
|
|
use diecoding\aws\s3\commands\GetUrlCommand; |
|
10
|
|
|
use diecoding\aws\s3\commands\PutCommand; |
|
11
|
|
|
use diecoding\aws\s3\commands\RestoreCommand; |
|
12
|
|
|
use diecoding\aws\s3\commands\UploadCommand; |
|
13
|
|
|
use diecoding\aws\s3\commands\ListCommand; |
|
14
|
|
|
use diecoding\aws\s3\interfaces; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class CommandFactory |
|
18
|
|
|
* |
|
19
|
|
|
* @package diecoding\aws\s3 |
|
20
|
|
|
*/ |
|
21
|
|
|
class CommandFactory |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var \diecoding\aws\s3\interfaces\CommandBuilder */ |
|
24
|
|
|
protected $builder; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* CommandFactory constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \diecoding\aws\s3\interfaces\CommandBuilder $builder |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(interfaces\CommandBuilder $builder) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->builder = $builder; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $filename |
|
38
|
|
|
* |
|
39
|
|
|
* @return \diecoding\aws\s3\commands\GetCommand |
|
40
|
|
|
*/ |
|
41
|
|
|
public function get(string $filename): GetCommand |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var GetCommand $command */ |
|
44
|
|
|
$command = $this->builder->build(GetCommand::class); |
|
45
|
|
|
$command->byFilename($filename); |
|
46
|
|
|
|
|
47
|
|
|
return $command; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $filename |
|
52
|
|
|
* @param mixed $body |
|
53
|
|
|
* |
|
54
|
|
|
* @return \diecoding\aws\s3\commands\PutCommand |
|
55
|
|
|
*/ |
|
56
|
|
|
public function put(string $filename, $body): PutCommand |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var PutCommand $command */ |
|
59
|
|
|
$command = $this->builder->build(PutCommand::class); |
|
60
|
|
|
$command->withFilename($filename)->withBody($body); |
|
61
|
|
|
|
|
62
|
|
|
return $command; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $filename |
|
67
|
|
|
* |
|
68
|
|
|
* @return \diecoding\aws\s3\commands\DeleteCommand |
|
69
|
|
|
*/ |
|
70
|
|
|
public function delete(string $filename): DeleteCommand |
|
71
|
|
|
{ |
|
72
|
|
|
/** @var DeleteCommand $command */ |
|
73
|
|
|
$command = $this->builder->build(DeleteCommand::class); |
|
74
|
|
|
$command->byFilename($filename); |
|
75
|
|
|
|
|
76
|
|
|
return $command; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $filename |
|
81
|
|
|
* @param mixed $source |
|
82
|
|
|
* |
|
83
|
|
|
* @return \diecoding\aws\s3\commands\UploadCommand |
|
84
|
|
|
*/ |
|
85
|
|
|
public function upload(string $filename, $source): UploadCommand |
|
86
|
|
|
{ |
|
87
|
|
|
/** @var UploadCommand $command */ |
|
88
|
|
|
$command = $this->builder->build(UploadCommand::class); |
|
89
|
|
|
$command->withFilename($filename)->withSource($source); |
|
90
|
|
|
|
|
91
|
|
|
return $command; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string $filename |
|
96
|
|
|
* @param int $days lifetime of the active copy in days |
|
97
|
|
|
* |
|
98
|
|
|
* @return \diecoding\aws\s3\commands\RestoreCommand |
|
99
|
|
|
*/ |
|
100
|
|
|
public function restore(string $filename, int $days): RestoreCommand |
|
101
|
|
|
{ |
|
102
|
|
|
/** @var RestoreCommand $command */ |
|
103
|
|
|
$command = $this->builder->build(RestoreCommand::class); |
|
104
|
|
|
$command->byFilename($filename)->withLifetime($days); |
|
105
|
|
|
|
|
106
|
|
|
return $command; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param string $filename |
|
111
|
|
|
* |
|
112
|
|
|
* @return \diecoding\aws\s3\commands\ExistCommand |
|
113
|
|
|
*/ |
|
114
|
|
|
public function exist(string $filename): ExistCommand |
|
115
|
|
|
{ |
|
116
|
|
|
/** @var ExistCommand $command */ |
|
117
|
|
|
$command = $this->builder->build(ExistCommand::class); |
|
118
|
|
|
$command->byFilename($filename); |
|
119
|
|
|
|
|
120
|
|
|
return $command; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param string $prefix |
|
125
|
|
|
* |
|
126
|
|
|
* @return \diecoding\aws\s3\commands\ListCommand |
|
127
|
|
|
*/ |
|
128
|
|
|
public function list(string $prefix): ListCommand |
|
129
|
|
|
{ |
|
130
|
|
|
/** @var ListCommand $command */ |
|
131
|
|
|
$command = $this->builder->build(ListCommand::class); |
|
132
|
|
|
$command->byPrefix($prefix); |
|
133
|
|
|
|
|
134
|
|
|
return $command; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param string $filename |
|
139
|
|
|
* |
|
140
|
|
|
* @return \diecoding\aws\s3\commands\GetUrlCommand |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getUrl(string $filename): GetUrlCommand |
|
143
|
|
|
{ |
|
144
|
|
|
/** @var GetUrlCommand $command */ |
|
145
|
|
|
$command = $this->builder->build(GetUrlCommand::class); |
|
146
|
|
|
$command->byFilename($filename); |
|
147
|
|
|
|
|
148
|
|
|
return $command; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param string $filename |
|
153
|
|
|
* @param mixed $expires |
|
154
|
|
|
* |
|
155
|
|
|
* @return \diecoding\aws\s3\commands\GetPresignedUrlCommand |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getPresignedUrl(string $filename, $expires): GetPresignedUrlCommand |
|
158
|
|
|
{ |
|
159
|
|
|
/** @var GetPresignedUrlCommand $command */ |
|
160
|
|
|
$command = $this->builder->build(GetPresignedUrlCommand::class); |
|
161
|
|
|
$command->byFilename($filename)->withExpiration($expires); |
|
162
|
|
|
|
|
163
|
|
|
return $command; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|