public function applyGlobalVarsToValue($value)
{
if (empty($this->globalVariablesCache)) {
$formats = \Scalr::config("scalr.system.global_variables.format");
// Get list of Server system vars
foreach ($this->GetScriptingVars() 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->envId, ScopeInterface::SCOPE_SERVER);
$vars = $gv->listVariables($this->GetFarmRoleObject()->RoleID, $this->farmId, $this->farmRoleId, $this->serverId);
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);
}