public static function replaceEnvVariables($yaml)
{
$matches = null;
preg_match_all('/%\\w+%/', $yaml, $matches);
$original_values = $matches[0];
$replace_values = [];
foreach ($original_values as $match) {
$env_variable = strtoupper(substr($match, 1, -1));
$env_variable = 'SCHEMATIC_' . $env_variable;
$env_value = getenv($env_variable);
if (!$env_value) {
throw new Exception(Craft::t("Schematic environment variable not set: {$env_variable}"));
}
$replace_values[] = $env_value;
}
return str_replace($original_values, $replace_values, $yaml);
}