AwsS3PublicUrlResolver   A
last analyzed

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 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