Completed
Pull Request — master (#1)
by Albin
01:57
created

AwsS3PublicUrlResolver::__construct()   A

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
class AwsS3PublicUrlResolver implements ResolverInterface
9
{
10
    /** @var S3Client */
11
    private $service;
12
13
    /** @var string */
14
    private $bucket;
15
16
    /** @var string */
17
    private $baseDir;
18
19
    /**
20
     * @param S3Client $service
21
     * @param string   $bucket  Bucket used by the adapter
22
     * @param string   $baseDir Base directory used by the adapter, if any
23
     */
24
    public function __construct(S3Client $service, $bucket, $baseDir = '')
25
    {
26
        $this->service = $service;
27
        $this->bucket  = $bucket;
28
        $this->baseDir = trim($baseDir, '/');
29
    }
30
31
    /**
32
     * Resolves given object $path into public URL.
33
     *
34
     * @param string $path
35
     *
36
     * @return string
37
     */
38
    public function resolve($path)
39
    {
40
        return $this->service->getObjectUrl(
41
            $this->bucket,
42
            ltrim($this->baseDir . '/' . ltrim($path, '/'), '/')
43
        );
44
    }
45
}
46