Completed
Push — master ( 0491a1...311634 )
by Freek
01:37
created

S3UrlGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getUrl() 0 4 1
A getTemporaryUrl() 0 7 1
A getPath() 0 4 1
1
<?php
2
3
namespace Spatie\MediaLibrary\UrlGenerator;
4
5
use DateTimeInterface;
6
use Illuminate\Filesystem\FilesystemManager;
7
use Illuminate\Contracts\Config\Repository as Config;
8
9
class S3UrlGenerator extends BaseUrlGenerator
10
{
11
    /** @var \Illuminate\Filesystem\FilesystemManager */
12
    protected $filesystemManager;
13
14
    public function __construct(Config $config, FilesystemManager $filesystemManager)
15
    {
16
        $this->filesystemManager = $filesystemManager;
17
18
        parent::__construct($config);
19
    }
20
21
    /**
22
     * Get the url for the profile of a media item.
23
     *
24
     * @return string
25
     */
26
    public function getUrl(): string
27
    {
28
        return config('medialibrary.s3.domain').'/'.$this->getPathRelativeToRoot();
29
    }
30
31
    /**
32
     * Get the temporary url for the profile of a media item.
33
     *
34
     * @param \DateTimeInterface $expiration
35
     * @param array              $options
36
     *
37
     * @return string
38
     */
39
    public function getTemporaryUrl(DateTimeInterface $expiration, array $options = []): string
40
    {
41
        return $this
42
            ->filesystemManager
43
            ->disk($this->media->getDiskDriverName())
44
            ->temporaryUrl($this->getPath(), $expiration, $options);
45
    }
46
47
    /**
48
     * Get the url for the profile of a media item.
49
     *
50
     * @return string
51
     */
52
    public function getPath(): string
53
    {
54
        return $this->getPathRelativeToRoot();
55
    }
56
}
57