Skip to content

Instantly share code, notes, and snippets.

@dzuelke
Created December 16, 2014 20:37
Show Gist options
  • Save dzuelke/8fbe0179a90bdca0007e to your computer and use it in GitHub Desktop.
Save dzuelke/8fbe0179a90bdca0007e to your computer and use it in GitHub Desktop.
crude %env:ENV_VARNAME% support for Symfony (diff from 2.5.7)
--- ParameterBag.php
+++ (clipboard)
@@ -221,7 +221,13 @@
// as the preg_replace_callback throw an exception when trying
// a non-string in a parameter value
if (preg_match('/^%([^%\s]+)%$/', $value, $match)) {
- $key = strtolower($match[1]);
+ $key = $match[1];
+
+ if(substr($key, 0, 4) === 'env:') {
+ $key = substr($key, 4);
+ return function($dynamic = false) use($key) { return $dynamic ? 'getenv('.var_export($key, true).')' : var_export(getenv($key), true); };
+ }
+ $key = strtolower($key);
if (isset($resolving[$key])) {
throw new ParameterCircularReferenceException(array_keys($resolving));
--- PhpDumper.php
+++ (clipboard)
@@ -1004,6 +1004,8 @@
throw new InvalidArgumentException(sprintf('You cannot dump a container with parameters that contain references to other services (reference to service "%s" found in "%s").', $value, $path.'/'.$key));
} elseif ($value instanceof Expression) {
throw new InvalidArgumentException(sprintf('You cannot dump a container with parameters that contain expressions. Expression "%s" found in "%s".', $value, $path.'/'.$key));
+ } elseif (is_callable($value)) {
+ $value = $value(true);
} else {
$value = var_export($value, true);
}
--- XmlDumper.php
+++ (clipboard)
@@ -319,6 +319,7 @@
*/
public static function phpToXml($value)
{
+ if(is_callable($value)) $value = $value();
switch (true) {
case null === $value:
return 'null';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment