* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\ParameterBag; use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; /** * @author Nicolas Grekas */ class EnvPlaceholderParameterBag extends ParameterBag { private $envPlaceholders = array(); private $providedTypes = array(); /** * {@inheritdoc} */ public function get($name) { if (0 === strpos($name, 'env(') && ')' === substr($name, -1) && 'env()' !== $name) { $env = substr($name, 4, -1); if (isset($this->envPlaceholders[$env])) { foreach ($this->envPlaceholders[$env] as $placeholder) { return $placeholder; // return first result } } if (!preg_match('/^(?:\w++:)*+\w++$/', $env)) { throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name)); } if ($this->has($name)) { $defaultValue = parent::get($name); if (null !== $defaultValue && !is_scalar($defaultValue)) { throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', gettype($defaultValue), $name)); } } $uniqueName = md5($name.uniqid(mt_rand(), true)); $placeholder = sprintf('env_%s_%s', str_replace(':', '_', $env), $uniqueName); $this->envPlaceholders[$env][$placeholder] = $placeholder; return $placeholder; } return parent::get($name); } /** * Returns the map of env vars used in the resolved parameter values to their placeholders. * * @return string[][] A map of env var names to their placeholders */ public function getEnvPlaceholders() { return $this->envPlaceholders; } /** * Merges the env placeholders of another EnvPlaceholderParameterBag. */ public function mergeEnvPlaceholders(self $bag) { if ($newPlaceholders = $bag->getEnvPlaceholders()) { $this->envPlaceholders += $newPlaceholders; foreach ($newPlaceholders as $env => $placeholders) { $this->envPlaceholders[$env] += $placeholders; } } } /** * Maps env prefixes to their corresponding PHP types. */ public function setProvidedTypes(array $providedTypes) { $this->providedTypes = $providedTypes; } /** * Gets the PHP types corresponding to env() parameter prefixes. * * @return string[][] */ public function getProvidedTypes() { return $this->providedTypes; } /** * {@inheritdoc} */ public function resolve() { if ($this->resolved) { return; } parent::resolve(); foreach ($this->envPlaceholders as $env => $placeholders) { if (!$this->has($name = "env($env)")) { continue; } if (is_numeric($default = $this->parameters[$name])) { $this->parameters[$name] = (string) $default; } elseif (null !== $default && !is_scalar($default)) { throw new RuntimeException(sprintf('The default value of env parameter "%s" must be scalar or null, %s given.', $env, gettype($default))); } } } } __halt_compiler();----SIGNATURE:----tC+Pw7jK9ZyTxes0ujFlOXB1L3XRgYda2ICd6nH198s/PcS5Lr2+Q5ghbV/tJ8Ml9p926hrSmOuWk8LohL3cRElvqF73IOR6dAdCGT901e7vO6JP3ds2XqfNUA9MLGTlnpcajnlG1Ca8hS2CkcnJay2FQvdNubFtUf2CCZGQ/Ka2iZzdOfT5f+6Z87JHfwVdXSneSI8KGI3MHiSxcSOdhsx8rHVfsA4PdsvyssX8MmLWU56dGF3VxhnMFGDLXk81+I54/kRMW9a/aN5DOjJ167Ea52y6q51Gj/+UogHldSAgaSzUJhOJXXo+6UJV4c8ExQDCNzSIoVlCfROvV/DAwSuBYO+phUW+9levSwVNQWkivoMihyrEzurRZNHDCJrQhuTCexI3T8Dm8EUEfwpuIZvmT7SgJBNaXblndCKvBIYtA9PfPKQxFSG31ZLR+iHJ/REtHva4KAG0PbSuc1VR3TvAUdLYPPYkzc/N2Dp9soCcD86yyTNHd12J7l/9eQMjV0Nc75Nvm5oQv6x8LATLlBhK5nD/Ouua/AKylYKI/s7moq+u+272/jbgd+72YRlZhp8hHBz36/Q/iSK3zG7Z4ZS4xMFsnRMxCwbAyi8PVDxWMqJb6OMjyNIMKWT3ZglNeXUCVuyksfAMZmEMXre1W84Y5Hu3TY/aSDgto8/zMkI=----ATTACHMENT:----MjMxMTU5NjE4NzUzMDkxNCA3ODg0NDU5MTAwOTcyODMwIDcyNTEwMjY2MzE4MjA0NDk=