-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeResolver.php
More file actions
98 lines (86 loc) · 2.37 KB
/
ThemeResolver.php
File metadata and controls
98 lines (86 loc) · 2.37 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Mods\Theme;
use InvalidArgumentException;
use Illuminate\Support\Collection;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Contracts\Config\Repository as ConfigContract;
class ThemeResolver
{
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The config instance.
*
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* Create a new theme reslover instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param \Illuminate\Contracts\Config\Repository $config
* @return void
*/
public function __construct(
Filesystem $files,
ConfigContract $config
) {
$this->files = $files;
$this->config = $config;
}
public function getActive($area = 'frontend')
{
return $this->config->get("theme.{$area}.active");
}
public function getPaths($area = 'frontend', $theme = null)
{
$paths = $this->activeThemeCollection($area, $theme)
->map(function ($theme, $key) {
return $theme->getPath();
});
return $paths;
}
public function activeThemeCollection($area = 'frontend', $theme = null)
{
if (!$theme) {
$theme = $this->getActive($area);
}
$themeCollection = Collection::make();
$active = $this->getTheme($theme, $area);
$themeCollection->put(null, $active);
while ($parent = $this->getParent($active)) {
$parent = $this->getTheme($parent, $area);
$themeCollection->put(null, $parent);
$active = $parent;
}
return $themeCollection;
}
public function themeCollection($area = 'frontend')
{
$themes = $this->config->get(
"theme.{$area}.themes",
[]
);
$themeCollection = Collection::make($themes);
return $themeCollection;
}
public function getTheme($key, $area)
{
$theme = $this->config->get(
"theme.{$area}.themes.{$key}",
false
);
if (!$theme) {
throw new InvalidArgumentException("Theme {$key} not found.");
}
return $theme;
}
protected function getParent($theme)
{
return $theme->getParent();
}
}