1 | <?php |
||
22 | class AmazonS3v3 extends AmazonS3 |
||
23 | { |
||
24 | use Cleanable; |
||
25 | |||
26 | /** |
||
27 | * Amazon S3 client. |
||
28 | * |
||
29 | * @var S3Client; |
||
30 | */ |
||
31 | protected $client; |
||
32 | |||
33 | /** |
||
34 | * Configure the sync. |
||
35 | * |
||
36 | * @see \phpbu\App\Backup\Sync::setup() |
||
37 | * @param array $config |
||
38 | * @throws \phpbu\App\Backup\Sync\Exception |
||
39 | * @throws \phpbu\App\Exception |
||
40 | */ |
||
41 | 12 | public function setup(array $config) |
|
47 | |||
48 | /** |
||
49 | * Execute the sync. |
||
50 | * |
||
51 | * @see \phpbu\App\Backup\Sync::sync() |
||
52 | * @param \phpbu\App\Backup\Target $target |
||
53 | * @param \phpbu\App\Result $result |
||
54 | * @throws \phpbu\App\Backup\Sync\Exception |
||
55 | */ |
||
56 | 3 | public function sync(Target $target, Result $result) |
|
76 | |||
77 | /** |
||
78 | * Create the AWS client. |
||
79 | * |
||
80 | * @return \Aws\S3\S3Client |
||
81 | */ |
||
82 | protected function createClient() : S3Client |
||
93 | |||
94 | /** |
||
95 | * Create a multi part s3 file uploader. |
||
96 | * |
||
97 | * @param \phpbu\App\Backup\Target $target |
||
98 | * @param \Aws\S3\S3Client $s3 |
||
99 | * @return \Aws\S3\MultipartUploader |
||
100 | */ |
||
101 | protected function createUploader(Target $target, S3Client $s3) : MultipartUploader |
||
108 | |||
109 | /** |
||
110 | * Creates collector for Amazon S3 |
||
111 | * |
||
112 | * @param \phpbu\App\Backup\Target $target |
||
113 | * @return \phpbu\App\Backup\Collector |
||
114 | */ |
||
115 | 1 | protected function createCollector(Target $target) : Collector |
|
116 | { |
||
117 | 1 | $path = new Path($this->pathRaw, $this->time); |
|
118 | 1 | return new Collector\AmazonS3v3($target, $path, $this->client, $this->bucket); |
|
119 | } |
||
120 | |||
121 | /** |
||
122 | * Simulate the sync execution. |
||
123 | * |
||
124 | * @param \phpbu\App\Backup\Target $target |
||
125 | * @param \phpbu\App\Result $result |
||
126 | */ |
||
127 | 1 | public function simulate(Target $target, Result $result) |
|
133 | |||
134 | /** |
||
135 | * Create a s3 bucket. |
||
136 | * |
||
137 | * @param \Aws\S3\S3Client $s3 |
||
138 | */ |
||
139 | 2 | private function createBucket(S3Client $s3) |
|
149 | |||
150 | /** |
||
151 | * Upload backup to Amazon S3 bucket. |
||
152 | * |
||
153 | * @param \phpbu\App\Backup\Target $target |
||
154 | * @param \Aws\S3\S3Client $s3 |
||
155 | * @throws \phpbu\App\Backup\Sync\Exception |
||
156 | * @throws \phpbu\App\Exception |
||
157 | */ |
||
158 | 3 | private function upload(Target $target, S3Client $s3) |
|
166 | |||
167 | /** |
||
168 | * Upload via stream wrapper. |
||
169 | * |
||
170 | * @param \phpbu\App\Backup\Target $target |
||
171 | * @param \Aws\S3\S3Client $s3 |
||
172 | * @throws \phpbu\App\Backup\Sync\Exception |
||
173 | */ |
||
174 | private function uploadStream(Target $target, S3Client $s3) |
||
184 | |||
185 | /** |
||
186 | * Upload via multi part. |
||
187 | * |
||
188 | * @param \phpbu\App\Backup\Target $target |
||
189 | * @param \Aws\S3\S3Client $s3 |
||
190 | * @param \Aws\Exception\MultipartUploadException |
||
191 | */ |
||
192 | 3 | private function uploadMultiPart(Target $target, S3Client $s3) |
|
197 | |||
198 | /** |
||
199 | * Open stream and validate it. |
||
200 | * |
||
201 | * @param string $path |
||
202 | * @param string $mode |
||
203 | * @return resource |
||
204 | * @throws \phpbu\App\Backup\Sync\Exception |
||
205 | */ |
||
206 | private function getFileHandle($path, $mode) |
||
214 | |||
215 | /** |
||
216 | * Get the s3 upload path |
||
217 | * |
||
218 | * @param \phpbu\App\Backup\Target $target |
||
219 | * @return string |
||
220 | */ |
||
221 | 2 | public function getUploadPath(Target $target) |
|
225 | } |
||
226 |