function EnvPlaceholderParameterBag::get
Overrides ParameterBag::get
File
-
vendor/
symfony/ dependency-injection/ ParameterBag/ EnvPlaceholderParameterBag.php, line 29
Class
- EnvPlaceholderParameterBag
- @author Nicolas Grekas <p@tchwork.com>
Namespace
Symfony\Component\DependencyInjection\ParameterBagCode
public function get(string $name) : array|bool|string|int|float|\UnitEnum|null {
if (str_starts_with($name, 'env(') && str_ends_with($name, ')') && 'env()' !== $name) {
$env = substr($name, 4, -1);
if (isset($this->envPlaceholders[$env])) {
foreach ($this->envPlaceholders[$env] as $placeholder) {
return $placeholder;
// return first result
}
}
if (isset($this->unusedEnvPlaceholders[$env])) {
foreach ($this->unusedEnvPlaceholders[$env] as $placeholder) {
return $placeholder;
// return first result
}
}
if (!preg_match('/^(?:[-.\\w\\\\]*+:)*+\\w*+$/', $env)) {
throw new InvalidArgumentException(\sprintf('The given env var name "%s" contains invalid characters (allowed characters: letters, digits, hyphens, backslashes and colons).', $name));
}
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {
throw new RuntimeException(\sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', get_debug_type($defaultValue), $name));
}
$uniqueName = hash('xxh128', $name . '_' . self::$counter++);
$placeholder = \sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.\\', '____'), $uniqueName);
$this->envPlaceholders[$env][$placeholder] = $placeholder;
return $placeholder;
}
return parent::get($name);
}