Completed
Push — master ( 3a2d63...6346ac )
by Albin
03:04
created

AwsS3PublicUrlResolver::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Gaufrette\Extras\Resolvable\Resolver;
4
5
use Aws\S3\S3Client;
6
use Gaufrette\Extras\Resolvable\ResolverInterface;
7
8
/**
9
 * Resolves objects' path into public URLs.
10
 */
11
class AwsS3PublicUrlResolver implements ResolverInterface
12
{
13
    /** @var S3Client */
14
    private $service;
15
16
    /** @var string */
17
    private $bucket;
18
19
    /** @var string */
20
    private $baseDir;
21
22
    /**
23
     * @param S3Client $service
24
     * @param string   $bucket  Bucket used by the adapter
25
     * @param string   $baseDir Base directory used by the adapter, if any
26
     */
27
    public function __construct(S3Client $service, $bucket, $baseDir = '')
28
    {
29
        $this->service = $service;
30
        $this->bucket  = $bucket;
31
        $this->baseDir = trim($baseDir, '/');
32
    }
33
34
    /**
35
     * Resolves given object $path into public URL.
36
     *
37
     * @param string $path
38
     *
39
     * @return string
40
     */
41
    public function resolve($path)
42
    {
43
        return $this->service->getObjectUrl(
44
            $this->bucket,
45
            ltrim($this->baseDir . '/' . ltrim($path, '/'), '/')
46
        );
47
    }
48
}
49