diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 087085e2d0..4d44da8e0d 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -118,3 +118,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c * added a SizeLength validator * improved the ImageValidator with min width, max width, min height, and max height constraints * added support for MIME with wildcard in FileValidator + +### Yaml + + * Yaml::parse() does not evaluate loaded files as PHP files by default anymore (call Yaml::enablePhpParsing() to get back the old behavior) diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index aad88fdc19..1bc6b2ee24 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -22,6 +22,13 @@ use Symfony\Component\Yaml\Exception\ParseException; */ class Yaml { + static public $enablePhpParsing = false; + + static public function enablePhpParsing() + { + self::$enablePhpParsing = true; + } + /** * Parses YAML into a PHP array. * @@ -44,23 +51,25 @@ class Yaml */ static public function parse($input) { - $file = ''; - // if input is a file, process it + $file = ''; if (strpos($input, "\n") === false && is_file($input) && is_readable($input)) { $file = $input; + if (self::$enablePhpParsing) { + ob_start(); + $retval = include($file); + $content = ob_get_clean(); - ob_start(); - $retval = include($input); - $content = ob_get_clean(); + // if an array is returned by the config file assume it's in plain php form else in YAML + $input = is_array($retval) ? $retval : $content; - // if an array is returned by the config file assume it's in plain php form else in YAML - $input = is_array($retval) ? $retval : $content; - } - - // if an array is returned by the config file assume it's in plain php form else in YAML - if (is_array($input)) { - return $input; + // if an array is returned by the config file assume it's in plain php form else in YAML + if (is_array($input)) { + return $input; + } + } else { + $input = file_get_contents($file); + } } $yaml = new Parser();