1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Module\Dependency\Parser\Config;
use Magento\Setup\Module\Dependency\ParserInterface;
/**
* Config xml parser
*/
class Xml implements ParserInterface
{
/**
* Template method. Main algorithm
*
* {@inheritdoc}
*/
public function parse(array $options)
{
$this->checkOptions($options);
$modules = [];
foreach ($options['files_for_parse'] as $file) {
$config = $this->getModuleConfig($file);
$modules[] = $this->extractModuleName($config);
}
return $modules;
}
/**
* Template method. Check passed options step
*
* @param array $options
* @return void
* @throws \InvalidArgumentException
*/
protected function checkOptions($options)
{
if (!isset(
$options['files_for_parse']
) || !is_array(
$options['files_for_parse']
) || !$options['files_for_parse']
) {
throw new \InvalidArgumentException('Parse error: Option "files_for_parse" is wrong.');
}
}
/**
* Template method. Extract module step
*
* @param \SimpleXMLElement $config
* @return string
*/
protected function extractModuleName($config)
{
return $this->prepareModuleName((string)$config->attributes()->name);
}
/**
* Template method. Load module config step
*
* @param string $file
* @return \SimpleXMLElement
*/
protected function getModuleConfig($file)
{
return \simplexml_load_file($file)->xpath('/config/module')[0];
}
/**
* Prepare module name
*
* @param string $name
* @return string
*/
protected function prepareModuleName($name)
{
return str_replace('_', '\\', $name);
}
}