Skip to content

Commit

Permalink
feature #13129 [Yaml] Removed the ability to parse a file in Yaml::pa…
Browse files Browse the repository at this point in the history
…rse() (saro0h)

This PR was merged into the 3.0-dev branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Commits
-------

e1c19f8 [Yaml] Removed the ability to parse a file in Yaml::parse()
  • Loading branch information
fabpot committed Dec 29, 2014
2 parents d6af4d6 + e1c19f8 commit 7dee89b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
9 changes: 0 additions & 9 deletions src/Symfony/Component/Yaml/Tests/YamlTest.php
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
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,
* 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 comments on commit 7dee89b

Please sign in to comment.