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

S3UrlGenerator::getUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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