From 07bd4694eb287b45eb822dc71bd19e6bafae3a8a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 28 Jun 2023 01:11:44 -0700 Subject: [PATCH] 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. --- setup/src/Setup/SettingsUtil.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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"; } } -- 2.25.1