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\Exception\RuntimeException; |
12
|
|
|
use Cecil\Step\AbstractStep; |
13
|
|
|
use Cecil\Util; |
14
|
|
|
use Symfony\Component\Yaml\Yaml; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Imports (themes) configuration. |
18
|
|
|
*/ |
19
|
|
|
class Import extends AbstractStep |
20
|
|
|
{ |
21
|
|
|
const THEME_CONFIG_FILE = 'config.yml'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function getName(): string |
27
|
|
|
{ |
28
|
|
|
return 'Importing themes configuration'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function init($options) |
35
|
|
|
{ |
36
|
|
|
if ($this->config->hasTheme()) { |
37
|
|
|
$this->canProcess = true; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
* |
44
|
|
|
* @throws RuntimeException |
45
|
|
|
*/ |
46
|
|
|
public function process() |
47
|
|
|
{ |
48
|
|
|
$themes = array_reverse((array) $this->config->getTheme()); |
49
|
|
|
$count = 0; |
50
|
|
|
$max = count($themes); |
51
|
|
|
foreach ($themes as $theme) { |
52
|
|
|
$count++; |
53
|
|
|
$themeConfigFile = $this->config->getThemesPath().'/'.$theme.'/'.self::THEME_CONFIG_FILE; |
54
|
|
|
$message = sprintf('"%s": no configuration file', $theme); |
55
|
|
|
if (Util\File::getFS()->exists($themeConfigFile)) { |
56
|
|
|
if (false === $config = Util\File::fileGetContents($themeConfigFile)) { |
57
|
|
|
throw new RuntimeException('Can\'t read the configuration file.'); |
58
|
|
|
} |
59
|
|
|
$themeConfig = Yaml::parse($config); |
60
|
|
|
$this->config->import($themeConfig); |
61
|
|
|
$message = sprintf('Theme "%s" imported', $theme); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->builder->getLogger()->info($message, ['progress' => [$count, $max]]); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|