-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Documented the new parseFile() method #8523
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,8 +92,8 @@ other dumps a PHP array to a YAML string | |
On top of these two classes, the :class:`Symfony\\Component\\Yaml\\Yaml` class | ||
acts as a thin wrapper that simplifies common uses. | ||
|
||
Reading YAML Files | ||
~~~~~~~~~~~~~~~~~~ | ||
Reading YAML Contents | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The :method:`Symfony\\Component\\Yaml\\Yaml::parse` method parses a YAML | ||
string and converts it to a PHP array: | ||
|
@@ -102,13 +102,8 @@ string and converts it to a PHP array: | |
|
||
use Symfony\Component\Yaml\Yaml; | ||
|
||
$value = Yaml::parse(file_get_contents('/path/to/file.yml')); | ||
|
||
.. caution:: | ||
|
||
Because it is currently possible to pass a filename to this method, you | ||
must validate the input first. Passing a filename is deprecated in | ||
Symfony 2.2, and was removed in Symfony 3.0. | ||
$value = Yaml::parse("foo: bar"); | ||
// $value = array('foo' => 'bar') | ||
|
||
If an error occurs during parsing, the parser throws a | ||
:class:`Symfony\\Component\\Yaml\\Exception\\ParseException` exception | ||
|
@@ -120,11 +115,26 @@ error occurred: | |
use Symfony\Component\Yaml\Exception\ParseException; | ||
|
||
try { | ||
$value = Yaml::parse(file_get_contents('/path/to/file.yml')); | ||
$value = Yaml::parse('...'); | ||
} catch (ParseException $e) { | ||
printf("Unable to parse the YAML string: %s", $e->getMessage()); | ||
printf('Unable to parse the YAML string: %s', $e->getMessage()); | ||
} | ||
|
||
Reading YAML Files | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
The :method:`Symfony\\Component\\Yaml\\Yaml::parseFile` method parses the YAML | ||
contents of the given file path and converts them to a PHP value:: | ||
|
||
use Symfony\Component\Yaml\Yaml; | ||
|
||
$value = Yaml::parseFile('/path/to/file.yml'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method is not static https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Yaml/Parser.php#L49 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but it is static in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're right! |
||
|
||
.. versionadded:: 3.4 | ||
The ``parseFile()`` method was introduced in Symfony 3.4. | ||
|
||
If an error occurs during parsing, the parser throws a ``ParseException`` exception. | ||
|
||
.. _components-yaml-dump: | ||
|
||
Writing YAML Files | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should already remove this block in the 3.3 docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #8554