Aws3Resolver::getUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/**
4
 * Copyright 2014 Jonathan Bouzekri. All rights reserved.
5
 *
6
 * @copyright Copyright 2014 Jonathan Bouzekri <[email protected]>
7
 * @license https://github.com/jbouzekri/FileUploaderBundle/blob/master/LICENSE
8
 * @link https://github.com/jbouzekri/FileUploaderBundle
9
 */
10
11
namespace Jb\Bundle\FileUploaderBundle\Service\Resolver;
12
13
use Aws\S3\S3Client;
14
15
/**
16
 * Aws3Resolver
17
 *
18
 * @author jobou
19
 */
20
class Aws3Resolver implements ResolverInterface
21
{
22
    /**
23
     * @var \Aws\S3\S3Client
24
     */
25
    protected $client;
26
27
    /**
28
     * @var string
29
     */
30
    protected $bucket;
31
32
    /**
33
     * @var string
34
     */
35
    protected $directory;
36
37
    /**
38
     * Constructor
39
     */
40
    public function __construct(S3Client $client, $bucket, $directory = null)
41
    {
42
        $this->client = $client;
43
        $this->bucket = $bucket;
44
        $this->directory = $directory;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getUrl($filename)
51
    {
52
        $path = $filename;
53
        if ($this->directory) {
54
            $path = sprintf('%s/%s', $this->directory, $path);
55
        }
56
57
        return $this->client->getObjectUrl($this->bucket, $path);
58
    }
59
}
60