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