|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace allejo\stakx\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Filesystem\Exception\FileNotFoundException; |
|
6
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
|
7
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
8
|
|
|
|
|
9
|
|
|
class ThemeManager extends FileManager |
|
10
|
|
|
{ |
|
11
|
|
|
const THEME_DEFINITION_FILE = "stakx-theme.yml"; |
|
12
|
|
|
|
|
13
|
|
|
private $themeFolder; |
|
14
|
|
|
private $themeFile; |
|
15
|
|
|
private $themeData; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct ($themeName, $includes = array(), $excludes = array()) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct(); |
|
20
|
|
|
|
|
21
|
|
|
$this->themeFolder = $this->fs->appendPath("_themes", $themeName); |
|
22
|
|
|
$this->themeFile = $this->fs->absolutePath($this->themeFolder, self::THEME_DEFINITION_FILE); |
|
23
|
|
|
$this->themeData = array( |
|
24
|
|
|
'exclude' => array(), |
|
25
|
|
|
'include' => array() |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
if (!$this->fs->exists($this->themeFolder)) |
|
29
|
|
|
{ |
|
30
|
|
|
throw new FileNotFoundException("The '${themeName}' theme folder could not be found.'"); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($this->fs->exists($this->themeFile)) |
|
34
|
|
|
{ |
|
35
|
|
|
$themeData = Yaml::parse(file_get_contents($this->themeFile)); |
|
36
|
|
|
|
|
37
|
|
|
$this->themeData = array_merge_recursive($this->themeData, $themeData); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
foreach ($this->themeData['include'] as &$include) |
|
41
|
|
|
{ |
|
42
|
|
|
$include = $this->fs->appendPath($this->themeFolder, $include); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->finder = $this->fs->getFinder( |
|
46
|
|
|
array_merge( |
|
47
|
|
|
$includes, |
|
48
|
|
|
$this->themeData['include'] |
|
49
|
|
|
), |
|
50
|
|
|
array_merge( |
|
51
|
|
|
$excludes, |
|
52
|
|
|
$this->themeData['exclude'], |
|
53
|
|
|
array('.twig') |
|
54
|
|
|
), |
|
55
|
|
|
$this->fs->absolutePath($this->themeFolder) |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function copyFiles () |
|
60
|
|
|
{ |
|
61
|
|
|
$this->output->notice('Copying theme files...'); |
|
62
|
|
|
|
|
63
|
|
|
/** @var SplFileInfo $file */ |
|
64
|
|
|
foreach ($this->finder as $file) |
|
65
|
|
|
{ |
|
66
|
|
|
if ($this->tracking) |
|
67
|
|
|
{ |
|
68
|
|
|
$fileName = $this->fs->appendPath($this->themeFolder, $file->getRelativePathname()); |
|
69
|
|
|
$this->files[$fileName] = $file; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->copyToCompiledSite($file, $this->themeFolder); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function copyFile($filePath) |
|
77
|
|
|
{ |
|
78
|
|
|
if ($this->isFileAsset($filePath)) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->output->notice('Copying theme asset: {file}', array('file' => $filePath)); |
|
81
|
|
|
|
|
82
|
|
|
$this->copyToCompiledSite($this->files[$filePath], $this->themeFolder); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |