* * 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:----uaoNhPQGBaOo2ELbyh3QjrjhRg7eIab8kXHxb9Z5pT2MnBvZdYnlL4FSDbKE/HDdnxEGVMVz9tEHD9FS2S4f1YG3qJKaCP7/d+7VhTb1+2PCNS2epz8zbJlME0LYb22oqyll5r9xsafnzfiIhQrCS1fcN5bUyVgNh45Fh/T2lhzb0vDce6du3UC7ztkVD5ZYO4+lo9ufH57vKMPQsYspao64X0h/l4Jal2pSakOe1j5WUOq+JKXf+XsMg2NmlRZ0Vp94PgPRVeLadWZR/YRd/A0/EJMGoqMD7kHUVlvSjwYZ2me5Jrxmj+4ZDZV6xEgwV+KTAottFJWCzs4FK/zIiMnjDsLnitlgBgGl3Lok+XbkC9NCXE31iogfigUU+wfbObsplxjn5d0GBuzM9RzT73/HKvgm0F5sZE3rFhkUfJ1VinvDimnEacsF0rpyOb5lm3zRi7wahLOiycja6QlGic9c1Pnf8m9S1oNj9BltE/mxM+NfoM9BrOMP4uNiUBoZ4gGWKlYgcHCUYS1xk1eOo4s8ZKDFq8BwT+ZsLNGK4lF8q6JmCI1Ujj6Cc6lUWGGLDbNig8IL7L4My4Fh7LDCm5ducZs5AGkrsJAD6fEMSlhFB0tr56n+XSDo8bGhEvKDQBmrVwI1rUO7dTH9RtnWCg2wAgSJifns7TOrnlUM9Ns=----ATTACHMENT:----NzM1ODQyMjY2MzA1MTQ3NCAzMzQyNjE4NzMyOTU2NjYgMzUzNzI4NDA4MDM4OTU4Mw==