diff --git a/src/Symfony/Component/Yaml/Tests/YamlTest.php b/src/Symfony/Component/Yaml/Tests/YamlTest.php index 633978d63b..53b0bfaaeb 100644 --- a/src/Symfony/Component/Yaml/Tests/YamlTest.php +++ b/src/Symfony/Component/Yaml/Tests/YamlTest.php @@ -21,7 +21,10 @@ class YamlTest extends \PHPUnit_Framework_TestCase $yml = Yaml::dump($data); $parsed = Yaml::parse($yml); $this->assertEquals($data, $parsed); + } + public function testParseFromFile() + { $filename = __DIR__.'/Fixtures/index.yml'; $contents = file_get_contents($filename); $parsedByFilename = Yaml::parse($filename); diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index 61793fb3ae..a4bf19c3fc 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -30,7 +30,7 @@ class Yaml * * Usage: * - * $array = Yaml::parse('config.yml'); + * $array = Yaml::parse(file_get_contents('config.yml')); * print_r($array); * * @@ -46,6 +46,8 @@ class Yaml * * @throws ParseException If the YAML is not valid * + * @deprecated The ability to pass file names to Yaml::parse() was deprecated in 2.7 and will be removed in 3.0. Please, pass the contents of the file instead. + * * @api */ public static function parse($input, $exceptionOnInvalidType = false, $objectSupport = false) @@ -53,6 +55,8 @@ class Yaml // if input is a file, process it $file = ''; if (strpos($input, "\n") === false && is_file($input)) { + trigger_error('The ability to pass file names to Yaml::parse() was deprecated in 2.7 and will be removed in 3.0. Please, pass the contents of the file instead.', E_USER_DEPRECATED); + if (false === is_readable($input)) { throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input)); }