Completed
Push — 2.1 ( 0d6728...0539a2 )
by Rafał
09:25
created

AwsAssetUrlGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A generateUrl() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2020 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2020 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Asset;
18
19
use Aws\S3\S3Client;
20
use SWP\Bundle\ContentBundle\Model\FileInterface;
21
22
final class AwsAssetUrlGenerator implements AssetUrlGeneratorInterface
23
{
24
    private $awsClient;
25
26
    private $awsBucket;
27
28
    private $awsPrefix;
29
30
    public function __construct(S3Client $awsClient, string $awsBucket = null, string $awsPrefix = null)
31
    {
32
        $this->awsClient = $awsClient;
33
        $this->awsBucket = $awsBucket;
34
        $this->awsPrefix = $awsPrefix;
35
    }
36
37
    public function generateUrl(FileInterface $file, string $basePath): string
38
    {
39
        $key = ($this->awsPrefix ? $this->awsPrefix.DIRECTORY_SEPARATOR : null).
40
            $basePath.
41
            DIRECTORY_SEPARATOR.
42
            $file->getAssetId().
43
            '.'.
44
            $file->getFileExtension()
45
        ;
46
47
        return $this->awsClient->getObjectUrl($this->awsBucket, $key);
48
    }
49
}
50