|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\MediaLibrary\UrlGenerator; |
|
4
|
|
|
|
|
5
|
|
|
use ByTIC\MediaLibrary\Conversions\Conversion; |
|
6
|
|
|
use ByTIC\MediaLibrary\Media\Media; |
|
7
|
|
|
use ByTIC\MediaLibrary\PathGenerator\AbstractPathGenerator; |
|
8
|
|
|
use League\Flysystem\FilesystemInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class AbstractUrlGenerator |
|
12
|
|
|
* @package ByTIC\MediaLibrary\UrlGenerator |
|
13
|
|
|
*/ |
|
14
|
|
|
class AbstractUrlGenerator implements UrlGeneratorInterface |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Media |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $media; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Conversion |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $conversion = null; |
|
26
|
|
|
|
|
27
|
|
|
public function getUrl(): string |
|
28
|
|
|
{ |
|
29
|
|
|
if (!$this->media->hasFile()) { |
|
30
|
|
|
return $this->media->getCollection()->getDefaultMediaUrl(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return $this->getDisk()->getUrl($this->getPath()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getPath(): string |
|
37
|
|
|
{ |
|
38
|
|
|
$convestion = $this->conversion instanceof Conversion ? $this->conversion->getName() : null; |
|
|
|
|
|
|
39
|
|
|
return $this->media->getPath($convestion); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function setMedia(Media $media): UrlGeneratorInterface |
|
43
|
|
|
{ |
|
44
|
|
|
$this->media = $media; |
|
45
|
|
|
|
|
46
|
|
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function setConversion(Conversion $conversion): UrlGeneratorInterface |
|
50
|
|
|
{ |
|
51
|
|
|
$this->conversion = $conversion; |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setPathGenerator(AbstractPathGenerator $pathGenerator): UrlGeneratorInterface |
|
57
|
|
|
{ |
|
58
|
|
|
$this->pathGenerator = $pathGenerator; |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// protected function getDiskName(): string |
|
64
|
|
|
// { |
|
65
|
|
|
// return $this->conversion === null |
|
66
|
|
|
// ? $this->media->disk |
|
67
|
|
|
// : $this->media->conversions_disk; |
|
68
|
|
|
// } |
|
69
|
|
|
|
|
70
|
|
|
protected function getDisk(): FilesystemInterface |
|
71
|
|
|
{ |
|
72
|
|
|
// return app('filesystem')->disk($this->getDiskName()); |
|
73
|
|
|
return $this->media->getFile()->getFilesystem(); |
|
74
|
|
|
} |
|
75
|
|
|
} |