Completed
Pull Request — master (#1)
by Albin
01:57
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
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