Completed
Push — master ( 43222d...21e595 )
by Sebastian
35:08
created

AmazonS3v2::sync()   B

Complexity

Conditions 2
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 2
eloc 15
nc 3
nop 2
1
<?php
2
namespace phpbu\App\Backup\Sync;
3
4
use Aws\S3\S3Client;
5
use phpbu\App\Result;
6
use phpbu\App\Backup\Sync;
7
use phpbu\App\Backup\Target;
8
use phpbu\App\Util\Arr;
9
use phpbu\App\Util\Str;
10
11
/**
12
 * Amazon S3 Sync
13
 *
14
 * @package    phpbu
15
 * @subpackage Backup
16
 * @author     Sebastian Feldmann <[email protected]>
17
 * @copyright  Sebastian Feldmann <[email protected]>
18
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
19
 * @link       http://phpbu.de/
20
 * @since      Class available since Release 1.1.4
21
 */
22
class AmazonS3v2 extends AmazonS3
23
{
24
    /**
25
     * Execute the sync.
26
     *
27
     * @see    \phpbu\App\Backup\Sync::sync()
28
     * @param  \phpbu\App\Backup\Target $target
29
     * @param  \phpbu\App\Result        $result
30
     * @throws \phpbu\App\Backup\Sync\Exception
31
     */
32
    public function sync(Target $target, Result $result)
33
    {
34
        $sourcePath = $target->getPathname();
35
        $targetPath = $this->path . $target->getFilename();
36
37
        $s3 = S3Client::factory(
1 ignored issue
show
Deprecated Code introduced by
The method Aws\AwsClient::factory() has been deprecated.

This method has been deprecated.

Loading history...
38
            [
39
                'signature' => 'v4',
40
                'region'    => $this->region,
41
                'credentials' => [
42
                    'key'    => $this->key,
43
                    'secret' => $this->secret,
44
                ]
45
            ]
46
        );
47
48
        try {
49
            $fh = fopen($sourcePath, 'r');
50
            $s3->upload($this->bucket, $targetPath, $fh, $this->acl);
51
        } catch (\Exception $e) {
52
            throw new Exception($e->getMessage(), null, $e);
53
        }
54
55
        $result->debug('upload: done');
56
    }
57
}
58