Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / dependency-injection / ParameterBag / EnvPlaceholderParameterBag.php
index d20e53531aa3b37a1cf2fe9ed5416dd3ea4d0489..12bc7612f9f0cc880e5ed4542377c8d91b3bfec6 100644 (file)
@@ -11,8 +11,8 @@
 
 namespace Symfony\Component\DependencyInjection\ParameterBag;
 
-use Symfony\Component\DependencyInjection\Exception\RuntimeException;
 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
+use Symfony\Component\DependencyInjection\Exception\RuntimeException;
 
 /**
  * @author Nicolas Grekas <p@tchwork.com>
@@ -20,6 +20,7 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 class EnvPlaceholderParameterBag extends ParameterBag
 {
     private $envPlaceholders = array();
+    private $providedTypes = array();
 
     /**
      * {@inheritdoc}
@@ -34,7 +35,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
                     return $placeholder; // return first result
                 }
             }
-            if (preg_match('/\W/', $env)) {
+            if (!preg_match('/^(?:\w++:)*+\w++$/', $env)) {
                 throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
             }
 
@@ -42,12 +43,12 @@ class EnvPlaceholderParameterBag extends ParameterBag
                 $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));
+                    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', $env, $uniqueName);
+            $placeholder = sprintf('env_%s_%s', str_replace(':', '_', $env), $uniqueName);
             $this->envPlaceholders[$env][$placeholder] = $placeholder;
 
             return $placeholder;
@@ -80,6 +81,24 @@ class EnvPlaceholderParameterBag extends ParameterBag
         }
     }
 
+    /**
+     * 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}
      */
@@ -91,13 +110,13 @@ class EnvPlaceholderParameterBag extends ParameterBag
         parent::resolve();
 
         foreach ($this->envPlaceholders as $env => $placeholders) {
-            if (!isset($this->parameters[$name = strtolower("env($env)")])) {
+            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)));
+                throw new RuntimeException(sprintf('The default value of env parameter "%s" must be scalar or null, %s given.', $env, \gettype($default)));
             }
         }
     }