66
77[ ![ SymfonyInsight] ( https://insight.symfony.com/projects/525fdfa3-d482-4218-b4b9-3c2efc305fac/big.svg )] ( https://insight.symfony.com/projects/525fdfa3-d482-4218-b4b9-3c2efc305fac )
88
9- This repository is a light Symfony bundle integrating the [ Flysystem] ( https://flysystem.thephpleague.com )
10- library into Symfony applications. It provides an efficient abstraction for the filesystem,
11- for instance to use local files in development and a cloud storage in production or to use a memory
12- filesystem in tests to increase their speed.
9+ flysystem-bundle is a Symfony bundle integrating the [ Flysystem] ( https://flysystem.thephpleague.com )
10+ library into Symfony applications.
1311
14- This bundle relies on
15- [ named aliases] ( https://symfony.com/doc/current/service_container/autowiring.html#dealing-with-multiple-implementations-of-the-same-type )
16- (introduced in Symfony 4.2) in order to create and configure multiple filesystems while still
17- following the best practices of software architecture (SOLID principles).
12+ It provides an efficient abstraction for the filesystem in order to change the storage backend depending
13+ on the execution environment (local files in development, cloud storage in production and memory in tests).
1814
1915## Installation
2016
@@ -26,7 +22,76 @@ You can install the bundle using Symfony Flex:
2622composer require league/flysystem-bundle
2723```
2824
29- ## Documentation
25+ ## Basic usage
26+
27+ The default configuration file created by Symfony Flex provides enough configuration to
28+ use Flysystem in your application as soon as you install the bundle:
29+
30+ ``` yaml
31+ # config/packages/flysystem.yaml
32+
33+ flysystem :
34+ storages :
35+ default.storage :
36+ adapter : ' local'
37+ options :
38+ directory : ' %kernel.project_dir%/var/storage/default'
39+ ` ` `
40+
41+ This configuration defines a single storage service (` default.storage`) based on the local adapter
42+ and configured to use the `%kernel.project_dir%/var/storage/default` directory.
43+
44+ For each storage defined under `flysystem.storages`, an associated service is created using the
45+ name you provide (in this case, a service `default.storage` will be created). The bundle also
46+ creates a named alias for each of these services.
47+
48+ This means you have two way of using the defined storages :
49+
50+ * either using autowiring, by typehinting against the `FilesystemInterface` and using the
51+ variable name matching one of your storages :
52+
53+ ` ` ` php
54+ use League\F lysystem\F ilesystemInterface;
55+
56+ class MyService
57+ {
58+ private $storage;
59+
60+ // The variable name $defaultStorage matters: it needs to be the camelized version
61+ // of the name of your storage.
62+ public function __construct(FilesystemInterface $defaultStorage)
63+ {
64+ $this->storage = $defaultStorage;
65+ }
66+
67+ // ...
68+ }
69+ ` ` `
70+
71+ The same goes for controllers :
72+
73+ ` ` ` php
74+ use League\F lysystem\F ilesystemInterface;
75+
76+ class MyController
77+ {
78+ // The variable name $defaultStorage matters: it needs to be the camelized version
79+ // of the name of your storage.
80+ public function index(FilesystemInterface $defaultStorage)
81+ {
82+ // ...
83+ }
84+ }
85+ ` ` `
86+
87+ * or using manual injection, by injecting the service named `default.storage` inside
88+ your services.
89+
90+ Once you have a FilesystemInterface, you can call methods from the
91+ [Filesystem API](https://flysystem.thephpleague.com/docs/usage/filesystem-api/)
92+ to interact with your storage.
93+
94+ # # Full documentation
3095
31961. [Getting started](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/1-getting-started.md)
32972. Cloud storage providers :
@@ -39,7 +104,8 @@ composer require league/flysystem-bundle
39104 [WebDAV](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#webdav)
401053. [Interacting with FTP and SFTP servers](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/3-interacting-with-ftp-and-sftp-servers.md)
411064. [Caching metadata in Symfony cache](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/4-caching-metadata-in-symfony-cache.md)
42- 5 . [ Creating a custom adapter] ( https://github.com/thephpleague/flysystem-bundle/blob/master/docs/5-creating-a-custom-adapter.md )
107+ 5. [Using a lazy adapter to switch storage backend using an environment variable](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/5-using-lazy-adapter-to-switch-at-runtime.md)
108+ 6. [Creating a custom adapter](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/6-creating-a-custom-adapter.md)
43109
44110* [Security issue disclosure procedure](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/A-security-disclosure-procedure.md)
45111* [Configuration reference](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/B-configuration-reference.md)
0 commit comments