The Filesystem component is a small package that provides convenient
utilities for common file system operations. It also abstracts the different
behavior of operating systems for some of those file system functions.
In Symfony 3.2 we improved it adding two new functions.
Added a cross-platform
readlink() function returns the target of a symbolic link. However,
its behavior is completely different under Windows and Unix. On Windows systems,
readlink() resolves recursively the children links of a link until a final
target is found. On Unix-based systems
readlink() only resolves the next link.
readlink() provided by the Filesystem component always behaves in
the same way:
public function readlink($path, $canonicalize = false)
$path does not exist or is not a link, it returns
$path is a link, it returns the next direct target of the link without
considering the existence of the target.
$path does not exist, it returns
$path exists, it returns its absolute fully resolved final version.
Although most of the times developers use soft or symbolic links, sometimes it's
convenient to create "hard links". The behavior of hard links is similar to the
way object references work: a hard link points to the exact same inode of the
target file and you can even rename the target file without breaking the hard link.
hardlink() method of the Filesystem component lets you create single
or multiple hard links to a given file:
$fs = new Filesystem();
// fileinode('file1.txt') === fileinode('hardlink1.lnk')
// multiple hardlinks pointing to the same file
$fs->hardlink('file2.txt', ['hardlink2.lnk', 'hardlink3.lnk']);
Help the Symfony project!
As with any Open-Source project, contributing
code or documentation is the most common way to help,
but we also have a wide range of sponsoring opportunities