-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
DefaultPathGenerator.php
46 lines (38 loc) · 1.16 KB
/
DefaultPathGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Spatie\MediaLibrary\Support\PathGenerator;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class DefaultPathGenerator implements PathGenerator
{
/*
* Get the path for the given media, relative to the root storage path.
*/
public function getPath(Media $media): string
{
return $this->getBasePath($media).'/';
}
/*
* Get the path for conversions of the given media, relative to the root storage path.
*/
public function getPathForConversions(Media $media): string
{
return $this->getBasePath($media).'/conversions/';
}
/*
* Get the path for responsive images of the given media, relative to the root storage path.
*/
public function getPathForResponsiveImages(Media $media): string
{
return $this->getBasePath($media).'/responsive-images/';
}
/*
* Get a unique base path for the given media.
*/
protected function getBasePath(Media $media): string
{
$prefix = config('media-library.prefix', '');
if ($prefix !== '') {
return $prefix.'/'.$media->getKey();
}
return $media->getKey();
}
}