8000 feature #6956 [Filesystem] Add documentation for the readlink method … · symfony/symfony-docs@2182353 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2182353

Browse files
committed
feature #6956 [Filesystem] Add documentation for the readlink method (tgalopin)
This PR was merged into the master branch. Discussion ---------- [Filesystem] Add documentation for the readlink method Following the merge of symfony/symfony#17498, this PR introduces documentation for the new methd `readlink`. Commits ------- 3572a3d [Filesystem] Add documentation for the readlink method
2 parents 649ee61 + 3572a3d commit 2182353

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

components/filesystem.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,40 @@ support symbolic links, a third boolean argument is available::
195195
// does not support symbolic links
196196
$fs->symlink('/path/to/source', '/path/to/destination', true);
197197

198+
readlink
199+
~~~~~~~~
200+
201+
.. versionadded:: 3.2
202+
The :method:`Symfony\\Component\\Filesystem\\Filesystem::readlink` method was introduced in Symfony 3.2.
203+
204+
:method:`Symfony\\Component\\Filesystem\\Filesystem::readlink` read links targets.
205+
206+
PHP's ``readlink()`` function returns the target of a symbolic link. However, its behavior
207+
is completely different under Windows and Unix. On Windows systems, ``readlink()``
208+
resolves recursively the children links of a link until a final target is found. On
209+
Unix-based systems ``readlink()`` only resolves the next link.
210+
211+
The :method:`Symfony\\Component\\Filesystem\\Filesystem::readlink` method provided
212+
by the Filesystem component always behaves in the same way::
213+
214+
// returns the next direct target of the link without considering the existence of the target
215+
$fs->readlink('/path/to/link');
216+
217+
// returns its absolute fully resolved final version of the target (if there are nested links, they are resolved)
218+
$fs->readlink('/path/to/link', true);
219+
220+
Its behavior is the following::
221+
222+
public function readlink($path, $canonicalize = false)
223+
224+
* When ``$canonicalize`` is ``false``:
225+
* if ``$path`` does not exist or is not a link, it returns ``null``.
226+
* if ``$path`` is a link, it returns the next direct target of the link without considering the existence of the target.
227+
228+
* When ``$canonicalize`` is ``true``:
229+
* if ``$path`` does not exist, it returns null.
230+
* if ``$path`` exists, it returns its absolute fully resolved final version.
231+
198232
makePathRelative
199233
~~~~~~~~~~~~~~~~
200234

0 commit comments

Comments
 (0)
0