1 | <?php |
||
14 | class XmlFileDefinitionCollection extends SiteDefinitionCollection |
||
15 | { |
||
16 | /** |
||
17 | * @var array Known config types [<name regexp>, <value regexp>, <type>] |
||
18 | */ |
||
19 | protected $configTypes = [ |
||
20 | ['(^defaultValue$)', '(^[1-9][0-9]*$)D', 'castToInt'], |
||
21 | ['(height$|width$)', '(^[1-9][0-9]*$)D', 'castToInt'], |
||
22 | ['(^required$)', '(^(?:true|false)$)iD', 'castToBool'] |
||
23 | ]; |
||
24 | |||
25 | /** |
||
26 | * Constructor |
||
27 | * |
||
28 | * @param string $path Path to site definitions' dir |
||
29 | */ |
||
30 | 15 | public function __construct($path) |
|
42 | |||
43 | /** |
||
44 | * Cast given config value to the appropriate type |
||
45 | * |
||
46 | * @param string $name Name of the config value |
||
47 | * @param string $value Config value in string form |
||
48 | * @return mixed Config value in appropriate type |
||
49 | */ |
||
50 | 14 | protected function castConfigValue($name, $value) |
|
62 | |||
63 | /** |
||
64 | * Cast given config value to a boolean |
||
65 | * |
||
66 | * @param string $value |
||
67 | * @return bool |
||
68 | */ |
||
69 | 14 | protected function castToBool($value) |
|
73 | |||
74 | /** |
||
75 | * Cast given config value to an integer |
||
76 | * |
||
77 | * @param string $value |
||
78 | * @return integer |
||
79 | */ |
||
80 | 14 | protected function castToInt($value) |
|
84 | |||
85 | /** |
||
86 | * Convert known config values to the appropriate type |
||
87 | * |
||
88 | * Will cast properties whose name is "defaultValue" or ends in "height" or "width" to integers |
||
89 | * |
||
90 | * @param array $config Original config |
||
91 | * @return array Converted config |
||
92 | */ |
||
93 | 14 | protected function convertValueTypes(array $config) |
|
109 | |||
110 | /** |
||
111 | * Replace arrays that contain a single element with the element itself |
||
112 | * |
||
113 | * @param array $config |
||
114 | * @return array |
||
115 | */ |
||
116 | 14 | protected function flattenConfig(array $config) |
|
128 | |||
129 | /** |
||
130 | * Extract a site's config from its XML file |
||
131 | * |
||
132 | * @param string $filepath Path to the XML file |
||
133 | * @return mixed |
||
134 | */ |
||
135 | 14 | protected function getConfigFromXmlFile($filepath) |
|
142 | |||
143 | /** |
||
144 | * Extract a site's config from its XML representation |
||
145 | * |
||
146 | * @param DOMElement $element Current node |
||
147 | * @return mixed |
||
148 | */ |
||
149 | 14 | protected function getElementConfig(DOMElement $element) |
|
166 | |||
167 | /** |
||
168 | * Extract a value from given element |
||
169 | * |
||
170 | * @param DOMElement $element |
||
171 | * @return mixed |
||
172 | */ |
||
173 | 14 | protected function getValueFromElement(DOMElement $element) |
|
179 | } |