AwsS3PublicUrlResolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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