Skip to content

Commit 742b2cc

Browse files
committed
[Filesystem] Document the readFile() method
1 parent 438031c commit 742b2cc

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)