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; |
10
|
|
|
|
11
|
|
|
use Cecil\Util; |
12
|
|
|
use Symfony\Component\Yaml\Yaml; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Import (themes) config. |
16
|
|
|
*/ |
17
|
|
|
class ConfigImport extends AbstractStep |
18
|
|
|
{ |
19
|
|
|
const THEME_CONFIG_FILE = 'config.yml'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function init($options) |
25
|
|
|
{ |
26
|
|
|
if ($this->config->hasTheme()) { |
27
|
|
|
$this->process = true; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function process() |
35
|
|
|
{ |
36
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['CONFIG', 'Importing config']); |
37
|
|
|
|
38
|
|
|
$themes = array_reverse($this->config->getTheme()); |
39
|
|
|
$count = 0; |
40
|
|
|
$max = count($themes); |
41
|
|
|
foreach ($themes as $theme) { |
42
|
|
|
$count++; |
43
|
|
|
$themeConfigFile = $this->config->getThemesPath().'/'.$theme.'/'.self::THEME_CONFIG_FILE; |
44
|
|
|
if (Util::getFS()->exists($themeConfigFile)) { |
45
|
|
|
set_error_handler( |
46
|
|
|
function ($severity, $message, $file, $line) { |
47
|
|
|
throw new \ErrorException($message, $severity, $severity, $file, $line); |
48
|
|
|
} |
49
|
|
|
); |
50
|
|
|
$config = file_get_contents($themeConfigFile); |
51
|
|
|
restore_error_handler(); |
52
|
|
|
$themeConfig = Yaml::parse($config); |
53
|
|
|
$this->config->import($themeConfig); |
54
|
|
|
$message = sprintf('%s: config imported', $theme); |
55
|
|
|
} else { |
56
|
|
|
$message = sprintf('%s: no config file', $theme); |
57
|
|
|
} |
58
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['CONFIG_PROGRESS', $message, $count, $max]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|