Completed
Push — master ( 144614...3a2d63 )
by Albin
13s
created

AwsS3PublicUrlResolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 38
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A resolve() 0 7 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