# Content

# Setup

composer require contributte/flysystem
1
extensions:
	flysystem: Contributte\Flysystem\DI\FlysystemExtension
1
2

# Configuration

flysystem:
	filesystem:
		default:
			adapter: League\Flysystem\Adapter\Local(%appDir%/../storage)
			autowired: true
			config: # $config parameter of League\Flysystem\Filesystem
				- disable_asserts: true
			plugins:
				- Your\Filesystem\Plugin()
	mountManager:
		plugins:
			- Your\MountManager\Plugin()
	plugins: # plugins for all filesystems and mount manager
		- Your\EverywhereUsed\Plugin()
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Minimal configuration is one filesystem with adapter, nothing more is required 😉

# Implementation

use League\Flysystem\Filesystem;
use League\Flysystem\MountManager;
use Nette\Application\UI\Presenter;

class FilePresenter extends Presenter
{

	/** @var Filesystem */
	private $filesystem;

	public function injectFilesystem(Filesystem $filesystem): void
	{
		$this->filesystem = $filesystem;
	}

	public function injectMountManager(MountManager $mountManager): void
	{
		// you can also get MountManager which has available all filesystems
		// it is not recommended and should be used only for transfer of files between filesystems
	}

	public function handleFileSave(): void
	{
		// get file and save its contents to $path
		$this->filesystem->write($path, $file->getContents());
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

If you miss something here so just look at League/Flysystem documentation (opens new window). This is only DI integration.