Flysystem Local Symlink Plugin
Requirements
Installation
Using composer:, (*1)
composer require falc/flysystem-local-symlink-plugin
Or add it manually:, (*2)
{
"require": {
"falc/flysystem-local-symlink-plugin": "1.*"
}
}
Usage
This plugin requires a Filesystem
instance using the Local adapter., (*3)
use Falc\Flysystem\Plugin\Symlink\Local as LocalSymlinkPlugin;
use League\Flysystem\Adapter\Local as LocalAdapter;
use League\Flysystem\Filesystem;
$filesystem = new Filesystem(new LocalAdapter('/'));
Symlink
Use symlink($target, $symlink)
to create a symlink., (*4)
$filesystem->addPlugin(new LocalSymlinkPlugin\Symlink());
$success = $filesystem->symlink('/tmp/some/target', '/tmp/symlink');
DeleteSymlink
Use deleteSymlink($symlink)
to delete a symlink., (*5)
$filesystem->addPlugin(new LocalSymlinkPlugin\DeleteSymlink());
$success = $filesystem->deleteSymlink('/tmp/symlink');
IsSymlink
Use isSymlink($filename)
to check if a file exists and is a symlink., (*6)
$filesystem->addPlugin(new LocalSymlinkPlugin\IsSymlink());
$isSymlink = $filesystem->isSymlink('/tmp/symlink');
Full and relative paths
The above examples show how to create symlinks using /
as root and full paths. But it is possible to use relative paths too., (*7)
use Falc\Flysystem\Plugin\Symlink\Local as LocalSymlinkPlugin;
use League\Flysystem\Adapter\Local as LocalAdapter;
use League\Flysystem\Filesystem;
$filesystem = new Filesystem(new LocalAdapter('/home/falc'));
$filesystem->addPlugin(new LocalSymlinkPlugin\Symlink());
$filesystem->addPlugin(new LocalSymlinkPlugin\IsSymlink());
$filesystem->addPlugin(new LocalSymlinkPlugin\DeleteSymlink());
// Result: /home/falc/flytest -> /home/falc/projects/cli/flytest
$filesystem->symlink('projects/cli/flytest', 'flytest');
// It is possible to check it or delete it in the same way:
$isSymlink = $filesystem->isSymlink('flytest');
$filesystem->deleteSymlink('flytest');