1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Cecil\Step\Themes; |
10
|
|
|
|
11
|
|
|
use Cecil\Step\AbstractStep; |
12
|
|
|
use Cecil\Util; |
13
|
|
|
use Symfony\Component\Yaml\Yaml; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Imports (themes) configuration. |
17
|
|
|
*/ |
18
|
|
|
class Import extends AbstractStep |
19
|
|
|
{ |
20
|
|
|
const THEME_CONFIG_FILE = 'config.yml'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function getName(): string |
26
|
|
|
{ |
27
|
|
|
return 'Importing themes configuration'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function init($options) |
34
|
|
|
{ |
35
|
|
|
if ($this->config->hasTheme()) { |
36
|
|
|
$this->canProcess = true; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function process() |
44
|
|
|
{ |
45
|
|
|
$themes = array_reverse((array) $this->config->getTheme()); |
46
|
|
|
$count = 0; |
47
|
|
|
$max = count($themes); |
48
|
|
|
foreach ($themes as $theme) { |
49
|
|
|
$count++; |
50
|
|
|
$themeConfigFile = $this->config->getThemesPath().'/'.$theme.'/'.self::THEME_CONFIG_FILE; |
51
|
|
|
$message = sprintf('"%s": no configuration file', $theme); |
52
|
|
|
if (Util\File::getFS()->exists($themeConfigFile)) { |
53
|
|
|
$config = Util\File::fileGetContents($themeConfigFile); |
54
|
|
|
if ($config === false) { |
55
|
|
|
throw new \Exception('Can\'t read the configuration file.'); |
56
|
|
|
} |
57
|
|
|
$themeConfig = Yaml::parse($config); |
58
|
|
|
$this->config->import($themeConfig); |
59
|
|
|
$message = sprintf('Theme "%s" imported', $theme); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->builder->getLogger()->info($message, ['progress' => [$count, $max]]); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|