NerdsAndCompany\Schematic\Models\Data::replaceEnvVariables PHP Метод

replaceEnvVariables() публичный статический Метод

Placeholders start with % and end with %. This will be replaced by the environment variable with the name SCHEMATIC_{PLACEHOLDER}. If the environment variable is not set an exception will be thrown.
public static replaceEnvVariables ( string $yaml ) : string
$yaml string
Результат string
    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);
    }