From: Tim Otten Date: Wed, 28 Jun 2023 08:11:44 +0000 (-0700) Subject: SettingsUtil::evaluate - Substitute variables atomically X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=07bd4694eb287b45eb822dc71bd19e6bafae3a8a;p=civicrm-core.git SettingsUtil::evaluate - Substitute variables atomically Iterative substitution allows silliness. It's not a specific problem because the range of inputs is so narrow here, but it's good cleanup the code-smell. --- diff --git a/setup/src/Setup/SettingsUtil.php b/setup/src/Setup/SettingsUtil.php index 2e217087b0..508d258902 100644 --- a/setup/src/Setup/SettingsUtil.php +++ b/setup/src/Setup/SettingsUtil.php @@ -77,12 +77,12 @@ class SettingsUtil { * Evaluated template. */ public static function evaluate(string $tplPath, array $params): string { - $str = file_get_contents($tplPath); - // FIXME: Use a single call to 'strtr($str, $vars)' + $template = file_get_contents($tplPath); + $vars = []; foreach ($params as $key => $value) { - $str = str_replace('%%' . $key . '%%', $value, $str); + $vars['%%' . $key . '%%'] = $value; } - return trim($str) . "\n"; + return trim(strtr($template, $vars)) . "\n"; } }