/
SkinFactory.php
58 lines (50 loc) · 1.44 KB
/
SkinFactory.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
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Concrete\Core\StyleCustomizer\Skin;
use Concrete\Core\Page\Theme\Theme;
use Concrete\Core\Utility\Service\Text;
use Illuminate\Filesystem\Filesystem;
class SkinFactory
{
/**
* @var Text
*/
protected $textService;
/**
* @var Filesystem
*/
protected $filesystem;
public function __construct(Filesystem $filesystem, Text $textService)
{
$this->filesystem = $filesystem;
$this->textService = $textService;
}
public function createFromPath(string $path, Theme $theme): ?SkinInterface
{
$fileName = basename($path);
$identifier = substr($fileName, 0, strpos($fileName, '.css'));
$skin = new PresetSkin($identifier, $this->textService->unhandle($identifier), $theme);
return $skin;
}
/**
* Returns an array of SkinInterface objects found in the path.
*
* @param string $path
*/
public function createMultipleFromDirectory(string $path, Theme $theme): array
{
$skins = [];
foreach($this->filesystem->directories($path) as $skin) {
$skin = $this->createFromPath($skin, $theme);
if ($skin) {
$skins[] = $skin;
}
}
foreach($this->filesystem->files($path) as $skin) {
$skin = $this->createFromPath($skin, $theme);
if ($skin) {
$skins[] = $skin;
}
}
return $skins;
}
}