Completed
Push — master ( 6a50c0...c1563b )
by Vladimir
02:57
created

ThemeManager::__construct()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 36
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 20
c 1
b 0
f 0
nc 5
nop 3
dl 0
loc 36
rs 8.5806
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
25
        if (!$this->fs->exists($this->themeFolder))
26
        {
27
            throw new FileNotFoundException("The '${themeName}' theme folder could not be found.'");
28
        }
29
30
        if ($this->fs->exists($this->themeFile))
31
        {
32
            $this->themeData = Yaml::parse(file_get_contents($this->themeFile));
33
        }
34
35
        foreach ($this->themeData['include'] as &$include)
36
        {
37
            $include = $this->fs->appendPath($this->themeFolder, $include);
38
        }
39
40
        $this->finder = $this->fs->getFinder(
41
            array_merge(
42
                $includes,
43
                $this->themeData['include']
44
            ),
45
            array_merge(
46
                $excludes,
47
                $this->themeData['exclude'],
48
                array('.twig')
49
            ),
50
            $this->fs->absolutePath($this->themeFolder)
51
        );
52
    }
53
54
    public function copyFiles ()
55
    {
56
        $this->output->notice('Copying theme files...');
57
58
        /** @var SplFileInfo $file */
59
        foreach ($this->finder as $file)
60
        {
61
            $this->files[] = $file;
62
            $this->copyToCompiledSite($file, $this->themeFolder);
63
        }
64
    }
65
}