function ParameterBag::resolveString
Resolves parameters inside a string.
Parameters
array $resolving An array of keys that are being resolved (used internally to detect circular references):
Throws
ParameterNotFoundException if a placeholder references a parameter that does not exist
ParameterCircularReferenceException if a circular reference if detected
RuntimeException when a given parameter has a type problem
1 call to ParameterBag::resolveString()
- ParameterBag::resolveValue in vendor/
symfony/ dependency-injection/ ParameterBag/ ParameterBag.php - Replaces parameter placeholders (%name%) by their values.
File
-
vendor/
symfony/ dependency-injection/ ParameterBag/ ParameterBag.php, line 219
Class
- ParameterBag
- Holds parameters.
Namespace
Symfony\Component\DependencyInjection\ParameterBagCode
public function resolveString(string $value, array $resolving = []) : mixed {
// we do this to deal with non string values (Boolean, integer, ...)
// as the preg_replace_callback throw an exception when trying
// a non-string in a parameter value
if (preg_match('/^%([^%\\s]+)%$/', $value, $match)) {
$key = $match[1];
if (isset($resolving[$key])) {
throw new ParameterCircularReferenceException(array_keys($resolving));
}
$resolving[$key] = true;
return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving);
}
return preg_replace_callback('/%%|%([^%\\s]+)%/', function ($match) use ($resolving, $value) {
// skip %%
if (!isset($match[1])) {
return '%%';
}
$key = $match[1];
if (isset($resolving[$key])) {
throw new ParameterCircularReferenceException(array_keys($resolving));
}
$resolved = $this->get($key);
if (!\is_string($resolved) && !is_numeric($resolved)) {
throw new RuntimeException(\sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type "%s" inside string value "%s".', $key, get_debug_type($resolved), $value));
}
$resolved = (string) $resolved;
$resolving[$key] = true;
return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving);
}, $value);
}