SignedUrlBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Media\Glide;
6
7
use Damax\Media\Domain\Image\UrlBuilder;
8
use Damax\Media\Domain\Model\MediaId;
9
use League\Glide\Signatures\SignatureInterface;
10
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
11
12
final class SignedUrlBuilder implements UrlBuilder
13
{
14
    private $urlGenerator;
15
    private $signature;
16
    private $routeName;
17
18
    public function __construct(UrlGeneratorInterface $urlGenerator, SignatureInterface $signature, string $routeName = 'media_image')
19
    {
20
        $this->urlGenerator = $urlGenerator;
21
        $this->signature = $signature;
22
        $this->routeName = $routeName;
23
    }
24
25
    public function build(MediaId $mediaId, array $params): string
26
    {
27
        $id = ['id' => (string) $mediaId];
28
29
        $url = $this->urlGenerator->generate($this->routeName, $id);
30
31
        $params = $this->signature->addSignature($url, $params);
32
33
        return $this->urlGenerator->generate($this->routeName, $params + $id);
34
    }
35
}
36