Completed
Push — master ( 5e0c9e...cd7596 )
by Alexandr
13:04
created

CustomPathGenerator::getBasePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Larrock\Core\Helpers;
4
5
use Spatie\MediaLibrary\Models\Media;
6
use Spatie\MediaLibrary\PathGenerator\PathGenerator;
7
8
/**
9
 * Изменение файловой структуры для загруженный файлов: ИмяМодели/исходный файл, ИмяМодели/ИмяФайла/пресеты
10
 * Class CustomPathGenerator
11
 *
12
 * @package App\Helpers
13
 */
14
class CustomPathGenerator implements PathGenerator
15
{
16
    /*
17
     * Get the path for the given media, relative to the root storage path.
18
     */
19
    public function getPath(Media $media): string
20
    {
21
        return $this->getBasePath($media).'/';
22
    }
23
24
    /*
25
     * Get the path for conversions of the given media, relative to the root storage path.
26
     */
27
    public function getPathForConversions(Media $media): string
28
    {
29
        return $this->getBasePath($media).'/conversions/';
30
    }
31
32
    /*
33
     * Get the path for responsive images of the given media, relative to the root storage path.
34
     */
35
    public function getPathForResponsiveImages(Media $media): string
36
    {
37
        return $this->getBasePath($media).'/responsive-images/';
38
    }
39
40
    /*
41
     * Get a unique base path for the given media.
42
     */
43
    protected function getBasePath(Media $media): string
44
    {
45
        return class_basename($media->model_type) .'/'. $media->name;
46
    }
47
}