Create File shortcut with Symfony2 FileSystem

606 Views Asked by At

Anyone know how to use the Filesystem component Symfony2 to create shortcut files? Or another way to create a file shortcut?

1

There are 1 best solutions below

2
Adam Elsodaney On
$filesystem = new Symfony\Component\Filesystem\Filesystem;

$filesystem->symlink($originDir, $targetDir, $copyOnWindows = false);

Reason to use Symfony Filesystem over the native PHP symlink would be because this method will prepare the directory for you, converts triggered errors into exceptions, and manages compatibility on Windows which doesn't support symlinks, so creates a copy instead.

Source: https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Filesystem/Filesystem.php#L289