private function _print_twig_array($theArray, $level)
{
$htmlText = "";
$i = 0;
$len = count($theArray);
foreach ($theArray as $key => $value) {
if ($i == $len - 1) {
$comma = "";
} else {
$comma = ",";
}
if (is_array($value)) {
if (empty($value)) {
$line = "\"" . $key . "\"" . ": [],\n";
$line = str_pad($line, strlen($line) + $level * 4, " ", STR_PAD_LEFT);
} else {
$keys = array_keys($value);
if ($keys[0] == "0") {
$predicate = ": [";
$suffix = "]" . $comma . "\n";
$subLines = "";
$numSubi = count($value);
$subi = 0;
foreach ($value as $subValue) {
$subi++;
if ($subi == $numSubi) {
$subComma = "";
} else {
$subComma = ",";
}
if (is_array($subValue)) {
$blockOpen = "{";
$blockOpen = str_pad($blockOpen, strlen($blockOpen) + ($level + 1) * 4, " ", STR_PAD_LEFT);
$blockClose = "}" . $subComma;
$blockClose = str_pad($blockClose, strlen($blockClose) + ($level + 1) * 4, " ", STR_PAD_LEFT);
$subLines = $subLines . "\n" . $blockOpen . "\n" . $this->_print_twig_array($subValue, $level + 2) . $blockClose;
if ($subi == $numSubi) {
$subLines .= "\n";
$suffix = str_pad($suffix, strlen($suffix) + $level * 4, " ", STR_PAD_LEFT);
}
} else {
$subLines .= "\"" . $subValue . "\"" . $subComma;
}
}
if ($level < 1) {
$predicate = "{% set " . $key . " = [ ";
$suffix = "] %}" . "\n\n";
$key = "";
} else {
$key = "\"" . $key . "\"";
}
$line = $key . $predicate;
$line = str_pad($line, strlen($line) + $level * 4, " ", STR_PAD_LEFT);
$line = $line . $subLines . $suffix;
} else {
$predicate = "\"" . $key . "\"" . ": { " . "\n";
$suffix = $comma;
if ($level < 1) {
$predicate = "{% set " . $key . " = { " . "\n";
$suffix = " %}" . "\n";
}
$predicate = str_pad($predicate, strlen($predicate) + $level * 4, " ", STR_PAD_LEFT);
$line = $this->_print_twig_array($value, $level + 1);
$suffix = "}" . $suffix . "\n";
$suffix = str_pad($suffix, strlen($suffix) + $level * 4, " ", STR_PAD_LEFT);
$line = $predicate . $line . $suffix;
}
}
} else {
if ($level < 1) {
$line = "{% set " . $key . " = \"" . htmlspecialchars($value, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . "\" %}" . "\n";
} else {
$line = "\"" . $key . "\"" . ": \"" . htmlspecialchars($value, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . "\"" . $comma . "\n";
$line = str_pad($line, strlen($line) + $level * 4, " ", STR_PAD_LEFT);
}
}
$htmlText = $htmlText . $line;
$i++;
}
return $htmlText;
}