public function applyGlobalVarsToValue($value)
{
if (empty($this->globalVariablesCache)) {
$formats = \Scalr::config("scalr.system.global_variables.format");
$systemVars = array('env_id' => $this->id, 'env_name' => $this->name);
// Get list of Server system vars
foreach ($systemVars as $name => $val) {
$name = "SCALR_" . strtoupper($name);
$val = trim($val);
if (isset($formats[$name])) {
$val = @sprintf($formats[$name], $val);
}
$this->globalVariablesCache[$name] = $val;
}
// Add custom variables
$gv = new Scalr_Scripting_GlobalVariables($this->clientId, $this->id, ScopeInterface::SCOPE_ENVIRONMENT);
$vars = $gv->listVariables();
foreach ($vars as $v) {
$this->globalVariablesCache[$v['name']] = $v['value'];
}
}
//Parse variable
$keys = array_keys($this->globalVariablesCache);
$keys = array_map(function ($item) {
return '{' . $item . '}';
}, $keys);
$values = array_values($this->globalVariablesCache);
$retval = str_replace($keys, $values, $value);
// Strip undefined variables & return value
return preg_replace("/{[A-Za-z0-9_-]+}/", "", $retval);
}