/**
* Replace tags with their values recursively
*
* @param string $text The template to process
* @param array $tags An associative array to replace in the template
*
* @return string Rendered mail template
*
* @since 4.0.0
*/
protected function replaceTags($text, $tags)
{
foreach ($tags as $key => $value) {
if (is_array($value)) {
$matches = array();
if (preg_match_all('/{' . strtoupper($key) . '}(.*?){\\/' . strtoupper($key) . '}/s', $text, $matches)) {
foreach ($matches[0] as $i => $match) {
$replacement = '';
foreach ($value as $subvalue) {
if (is_array($subvalue)) {
$replacement .= $this->replaceTags($matches[1][$i], $subvalue);
}
}
$text = str_replace($match, $replacement, $text);
}
}
} else {
$text = str_replace('{' . strtoupper($key) . '}', $value, $text);
}
}
return $text;
}