AssetPublisher::setFinder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php namespace Modules\Core\Foundation\Theme;
2
3
class AssetPublisher
4
{
5
    /**
6
     * @var \Illuminate\Filesystem\Filesystem
7
     */
8
    protected $finder;
9
    /**
10
     * @var ThemeManager
11
     */
12
    protected $repository;
13
14
    /**
15
     * @var Theme
16
     */
17
    private $theme;
18
19
    /**
20
     * @param Theme $theme
21
     */
22
    public function __construct(Theme $theme)
23
    {
24
        $this->theme = $theme;
25
    }
26
27
    /**
28
     * @param $finder
29
     * @return $this
30
     */
31
    public function setFinder($finder)
32
    {
33
        $this->finder = $finder;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @param $repository
40
     * @return $this
41
     */
42
    public function setRepository($repository)
43
    {
44
        $this->repository = $repository;
45
46
        return $this;
47
    }
48
49
    /**
50
     * Publish the assets
51
     */
52
    public function publish()
53
    {
54
        if (!$this->finder->isDirectory($sourcePath = $this->getSourcePath())) {
55
            $message = "Source path does not exist : {$sourcePath}";
56
            throw new \InvalidArgumentException($message);
57
        }
58
        if (!$this->finder->isDirectory($destinationPath = $this->getDestinationPath())) {
59
            $this->finder->makeDirectory($destinationPath, 0775, true);
60
        }
61
        if ($this->finder->copyDirectory($sourcePath, $destinationPath)) {
62
            return true;
63
        }
64
    }
65
66
    /**
67
     * Get the original source path
68
     * @return string
69
     */
70
    public function getSourcePath()
71
    {
72
        return $this->theme->getPath() . '/assets';
73
    }
74
75
    /**
76
     * Get the destination path
77
     * @return string
78
     */
79
    public function getDestinationPath()
80
    {
81
        return $this->repository->getAssetPath($this->theme->getLowerName());
82
    }
83
}
84