Commit 19a2b365 authored by Cerdic's avatar Cerdic

mise en forme de la config

parent 9e150245
......@@ -35,7 +35,7 @@ class OfflineBuildServices extends Command {
include_spip('inc/texte');
include_spip('inc/print');
$output->writeln(filtre_print_dist($config, "\n"));
$output->writeln(OfflineBuildServices::printConfig($config));
$output->writeln("<info>Service buildé</info>");
}
else {
......@@ -43,4 +43,47 @@ class OfflineBuildServices extends Command {
}
}
public static function printConfig($u, $join = "\n", $indent = 0) {
if (is_string($u)) {
return $u;
}
// caster $u en array si besoin
if (is_object($u)) {
$u = (array)$u;
}
if (is_array($u)) {
$out = "";
// sinon on passe a la ligne et on indente
$i_str = str_pad("", $indent, " ");
// toutes les cles sont numeriques ?
// et aucun enfant n'est un tableau
// liste simple separee par des virgules
$numeric_keys = array_map('is_numeric', array_keys($u));
$array_values = array_map('is_array', $u);
$object_values = array_map('is_object', $u);
if (array_sum($numeric_keys) == count($numeric_keys)
and !array_sum($array_values)
and !array_sum($object_values)
) {
foreach ($u as $v) {
$out .= $join . $i_str . "" . $v;
}
}
else {
foreach ($u as $k => $v) {
$out .= $join . $i_str . "$k: " . OfflineBuildServices::printConfig($v, $join, $indent + 2);
}
}
return $out;
}
// on sait pas quoi faire...
return $u;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment