HB/onyx2/require/parse.php
Nigel dd61d3b66b Ajout d'une étape de linting dans DroneCi (#3)
Corrige un doublons laissé par le rebase semi-manuel

Ajout d'une étape de linting dans DroneCi

Fix linting

Co-authored-by: Nigel Sheldon <nigelsheldon@live.fr>
Reviewed-on: https://gitea.nemunai.re/halo-battle/game/pulls/3
2020-11-21 18:54:32 +00:00

70 lines
2.2 KiB
PHP

<?php
function parse_config($node, $name = 'var', $attribut = 'name')
{
$configs = $node->childNodes;
if ($configs) {
$array = array();
foreach ($configs as $value) {
if ($value->nodeName == $name) {
if ($value->getElementsByTagName($name)->length == 0) {
$array[$value->getAttribute($attribut)] = trim($value->textContent);
} else {
$array[$value->getAttribute($attribut)] = parse_config($value, $name, $attribut);
}
}
}
return $array;
} else {
return array();
}
}
/*function parse($file)
{
$xml = new DOMDocument();
$xml->load($file);
#$xml->validate();
if($root = $xml->documentElement->getAttribute('root'))
{
if($root == substr(FILE,0,strlen($root)))
{
$search = substr(FILE,strlen($root));
$paths = explode('/',$search);
$paths2 = $paths;
foreach($paths as $key => $path)
{
for($i = $key - 1; $i >= 0; $i--)
{
$paths2[$key] = $paths[$i] . '/' . $paths2[$key];
}
if($key != count($paths) - 1) $paths2[$key] .= '/';
}
foreach($xml->getElementsByTagName('config') as $value)
{
$config[$value->getAttribute('match')] = $value;
}
$parsed = array();
array_unshift($paths2,'*');
foreach($paths2 as $path)
{
if($config[$path]) $parsed = array_merge($parsed,parse_config($config[$path]));
}
return $parsed;
}
}
else return FALSE;
}
define('FILE','/var/www/site/test/test.php');
print_r(parse('../config/root.xml'));*/