Skip to content

Commit 6fb8d69

Browse files
committed
minor #19689 [Filesystem] Document the readFile() method (javiereguiluz)
This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [Filesystem] Document the readFile() method Fixes #19680. Commits ------- 742b2cc [Filesystem] Document the readFile() method
2 parents 438031c + 742b2cc commit 6fb8d69

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

components/filesystem.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,22 @@ contents at the end of some file::
313313
If either the file or its containing directory doesn't exist, this method
314314
creates them before appending the contents.
315315

316+
``readFile``
317+
~~~~~~~~~~~~
318+
319+
.. versionadded:: 7.1
320+
321+
The ``readFile()`` method was introduced in Symfony 7.1.
322+
323+
:method:`Symfony\\Component\\Filesystem\\Filesystem::readFile` returns all the
324+
contents of a file as a string. Unlike the :phpfunction:`file_get_contents` function
325+
from PHP, it throws an exception when the given file path is not readable and
326+
when passing the path to a directory instead of a file::
327+
328+
$contents = $filesystem->readFile('/some/path/to/file.txt');
329+
330+
The ``$contents`` variable now stores all the contents of the ``file.txt`` file.
331+
316332
Path Manipulation Utilities
317333
---------------------------
318334

0 commit comments

Comments
 (0)