Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
XmlFileDefinitionCollection.php
01 <?php
02
03 /*
04 * @package s9e\TextFormatter
05 * @copyright Copyright (c) 2010-2016 The s9e Authors
06 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
07 */
08 namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator\Collections;
09 use DOMDocument;
10 use DOMElement;
11 use InvalidArgumentException;
12 class XmlFileDefinitionCollection extends SiteDefinitionCollection
13 {
14 public function __construct($path)
15 {
16 if (!\file_exists($path) || !\is_dir($path))
17 throw new InvalidArgumentException('Invalid site directory');
18 foreach (\glob($path . '/*.xml') as $filepath)
19 {
20 $siteId = \basename($filepath, '.xml');
21 $this->items[$siteId] = $this->getConfigFromXmlFile($filepath);
22 }
23 }
24 protected function flattenConfig(array $config)
25 {
26 foreach ($config as $k => $v)
27 if (\is_array($v) && \count($v) === 1)
28 $config[$k] = \end($v);
29 return $config;
30 }
31 protected function getConfigFromXmlFile($filepath)
32 {
33 $dom = new DOMDocument;
34 $dom->load($filepath);
35 return $this->getElementConfig($dom->documentElement);
36 }
37 protected function getElementConfig(DOMElement $element)
38 {
39 $config = array();
40 foreach ($element->attributes as $attribute)
41 $config[$attribute->name][] = $attribute->value;
42 foreach ($element->childNodes as $childNode)
43 if ($childNode instanceof DOMElement)
44 $config[$childNode->nodeName][] = $this->getValueFromElement($childNode);
45 return $this->flattenConfig($config);
46 }
47 protected function getValueFromElement(DOMElement $element)
48 {
49 return (!$element->attributes->length && $element->childNodes->length === 1)
50 ? $element->nodeValue
51 : $this->getElementConfig($element);
52 }
53 }