Integration of Flysystem into Nette Framework including support Flysystem Plugins.
Via Composer
$ composer require surda/flysystem
and add to config.neon
extensions:
flysystem: Surda\Flysystem\Bridges\NetteDI\FlysystemExtension
Example with Local Adapter.
flysystem:
filesystem:
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
use League\Flysystem\Filesystem;
class Foo
{
/** @var Filesystem */
private $filesystem;
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}
public function save()
{
$this->filesystem->write('path/to/file.txt', 'contents');
}
}
Example with Local Adapters.
flysystem:
mountmanager:
filesystems:
local:
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
backup:
adapter: League\Flysystem\Adapter\Local('/path/to/backup/folder')
...
use League\Flysystem\MountManager;
class Bar
{
/** @var MountManager */
private $manager;
public function __construct(MountManager $manager)
{
$this->manager = $manager;
}
public function backup()
{
$this->manager->copy('local://path/to/file.txt', 'backup://storage/file.txt');
}
}
Configuration if the adapter constructor accepts a string.
flysystem:
filesystem:
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
# or
adapter: League\Flysystem\Adapter\Local
arguments: '/path/to/folder'
Configuration if the adapter constructor accepts a array.
flysystem:
filesystem:
adapter: League\Flysystem\Adapter\Ftp( { host: 'ftp.example.com', username: 'username', password: 'password' } )
# or
adapter: League\Flysystem\Adapter\Ftp
arguments:
host: 'ftp.example.com'
username: 'username'
password: 'password'
Configuration if the adapter constructor accepts a client object.
flysystem:
filesystem:
adapter: Srmklive\Dropbox\Adapter\DropboxAdapter( Srmklive\Dropbox\Client\DropboxClient('access_token'), '/' )
Adapter in Mountmanager.
flysystem:
mountmanager:
filesystems:
local:
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
# or
adapter: League\Flysystem\Adapter\Local
arguments: '/path/to/folder'
backup:
adapter: League\Flysystem\Adapter\Local('/path/to/backup/folder')
# or
adapter: League\Flysystem\Adapter\Local
arguments: '/path/to/backup/folder'
Adding plugins to all Filesystems and Mountmanager.
flysystem:
plugins:
- League\Flysystem\Plugin\ListFiles()
- League\Flysystem\Plugin\ListPaths()
Adding plugins only to Filesystem.
flysystem:
filesystem:
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
plugins:
- Namespace\MyPlugin1()
- Namespace\MyPlugin2()
- ...
Adding plugins only to specific Filesystem in Mountmanager.
flysystem:
mountmanager:
filesystems:
local:
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
plugins:
- Namespace\MyPlugin1()
- Namespace\MyPlugin2()
backup:
adapter: League\Flysystem\Adapter\Local('/path/to/backup/folder')
plugins:
- Namespace\MyPlugin3()
- Namespace\MyPlugin4()
Adding plugins only to Mountmanager.
flysystem:
mountmanager:
plugins:
- Namespace\MyPlugin5()
- Namespace\MyPlugin6()
flysystem:
filesystem:
adapter: League\Flysystem\Adapter\Local('/path/to/folder', { key: value, foo: bar } )
# or
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
config: { key: value, foo: bar }
# or
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
config:
key: value
foo: bar
// Generated services
/**
* @return League\Flysystem\Filesystem
*/
public function createServiceFlysystem__filesystem()
{
$service = new League\Flysystem\Filesystem($this->getService('flysystem.filesystem.adapter'),
['key' => 'value', 'foo' => 'bar']);
return $service;
}
/**
* @return League\Flysystem\Adapter\Local
*/
public function createServiceFlysystem__filesystem__adapter()
{
$service = new League\Flysystem\Adapter\Local('/var/www/nette/sandbox/www/files');
return $service;
}
Config argument in Mountmanager.
flysystem:
mountmanager:
filesystems:
local:
adapter: League\Flysystem\Adapter\Local('/path/to/folder', { key: value, foo: bar } )
# or
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
config: { key: value, foo: bar }
# or
adapter: League\Flysystem\Adapter\Local('/path/to/folder')
config:
key: value
foo: bar
...