8000 [Yaml] Removed the ability to parse a file in Yaml::parse() by saro0h · Pull Request #13129 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Yaml] Removed the ability to parse a file in Yaml::parse() #13129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/Symfony/Component/Yaml/Tests/YamlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,4 @@ public function testParseAndDump()
$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);
$parsedByContents = Yaml::parse($contents);
$this->assertEquals($parsedByFilename, $parsedByContents);
}
}
31 changes: 2 additions & 29 deletions src/Symfony/Component/Yaml/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,21 @@ class Yaml
* print_r($array);
* </code>
*
* As this method accepts both plain strings and file names as an input,< AE30 /span>
* you must validate the input before calling this method. Passing a file
* as an input is a deprecated feature and will be removed in 3.0.
*
* @param string $input Path to a YAML file or a string containing YAML
* @param string $input A string containing YAML
* @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
* @param bool $objectSupport True if object support is enabled, false otherwise
*
* @return array The YAML converted to a PHP array
*
* @throws ParseException If the YAML is not valid
*
* @deprecated The ability to pass file names to Yaml::parse() was deprecated in 2.2 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)
{
// 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.2 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));
}

$file = $input;
$input = file_get_contents($file);
}

$yaml = new Parser();

try {
return $yaml->parse($input, $exceptionOnInvalidType, $objectSupport);
} catch (ParseException $e) {
if ($file) {
$e->setParsedFile($file);
}

throw $e;
}
return $yaml->parse($input, $exceptionOnInvalidType, $objectSupport);
}

/**
Expand Down
0