<?php private static function replaceKeys(string $template, string $key, string $pattern): string {
if (preg_match_all($pattern, $template, $key_matches) > 0) {
foreach (array_unique($key_matches[0]) as $key_match) {
$template = strtr($template, [$key_match => $key]);
}
}
return $template;