Skip to content

Commit bd0f219

Browse files
javiereguiluzmaxhelias
authored andcommitted
Update README
1 parent a5fd6b6 commit bd0f219

File tree

1 file changed

+68
-54
lines changed

1 file changed

+68
-54
lines changed

README.md

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# flysystem-bundle
22

33
[![Packagist Version](https://img.shields.io/packagist/v/league/flysystem-bundle.svg?style=flat-square)](https://packagist.org/packages/league/flysystem-bundle)
4-
[![Software license](https://img.shields.io/github/license/thephpleague/flysystem-bundle.svg?style=flat-square)](https://github.com/thephpleague/flysystem-bundle/blob/master/LICENSE)
4+
[![Software license](https://img.shields.io/github/license/thephpleague/flysystem-bundle.svg?style=flat-square)](LICENSE)
55

66
flysystem-bundle is a Symfony bundle integrating the [Flysystem](https://flysystem.thephpleague.com)
77
library into Symfony applications.
@@ -12,7 +12,7 @@ on the execution environment (local files in development, cloud storage in produ
1212
> Note: you are reading the documentation for flysystem-bundle 3.0, which relies on Flysystem 3.
1313
> If you use Flysystem 1.x, use [flysystem-bundle 1.x](https://github.com/thephpleague/flysystem-bundle/tree/1.x).
1414
> If you use Flysystem 2.x, use [flysystem-bundle 2.x](https://github.com/thephpleague/flysystem-bundle/tree/2.x).
15-
> Read the [Upgrade guide](https://github.com/thephpleague/flysystem-bundle/blob/master/UPGRADE.md) to learn how to upgrade.
15+
> Read the [Upgrade guide](UPGRADE.md) to learn how to upgrade.
1616
1717
## Installation
1818

@@ -51,76 +51,90 @@ For each storage defined under `flysystem.storages`, an associated service is cr
5151
name you provide (in this case, a service `default.storage` will be created). The bundle also
5252
creates a named alias for each of these services.
5353

54-
This means you have two ways of using the defined storages:
54+
This means you can inject the storage services in your services and controllers like this:
5555

56-
* either using autowiring, by typehinting against the `FilesystemOperator` and using the
57-
variable name matching one of your storages:
56+
**1) Using service autowiring:** typehint your service/controller argument with
57+
`FilesystemOperator` and use the `#[Target]` attribute to select the storage by name:
5858

59-
```php
60-
use League\Flysystem\FilesystemOperator;
61-
62-
class MyService
63-
{
64-
private FilesystemOperator $storage;
65-
66-
// The variable name $defaultStorage matters: it needs to be the camelized version
67-
// of the name of your storage.
68-
public function __construct(FilesystemOperator $defaultStorage)
69-
{
70-
$this->storage = $defaultStorage;
71-
}
72-
73-
// ...
59+
```php
60+
use League\Flysystem\FilesystemOperator;
61+
62+
class MyService
63+
{
64+
public function __construct(
65+
#[Target('default.storage')] private FilesystemOperator $storage,
66+
) {
7467
}
75-
```
76-
77-
The same goes for controllers:
78-
79-
```php
80-
use League\Flysystem\FilesystemOperator;
81-
82-
class MyController
68+
69+
// ...
70+
}
71+
```
72+
73+
Instead of using the `#[Target]` attribute, you can also typehint your service/controller
74+
argument with `FilesystemOperator` and use the camelCase version of your storage
75+
name as the variable name. However, this practice is discouraged and won't work in
76+
future Symfony versions:
77+
78+
```php
79+
use League\Flysystem\FilesystemOperator;
80+
81+
class MyService
82+
{
83+
private FilesystemOperator $storage;
84+
85+
// The variable name $defaultStorage matters: it needs to be the
86+
// camelCase version of the name of your storage (foo.bar.baz -> fooBarBaz)
87+
public function __construct(FilesystemOperator $defaultStorage)
8388
{
84-
// The variable name $defaultStorage matters: it needs to be the camelized version
85-
// of the name of your storage.
86-
public function index(FilesystemOperator $defaultStorage)
87-
{
88-
// ...
89-
}
89+
$this->storage = $defaultStorage;
9090
}
91-
```
9291
93-
* or using manual injection, by injecting the service named `default.storage` inside
94-
your services.
92+
// ...
93+
}
94+
```
95+
96+
**2) Using manual service registration:** in your services, inject the service
97+
that this bundle creates for each of your storages following the pattern
98+
`'flysystem.adapter.'.$storageName`:
99+
100+
```yaml
101+
# config/services.yaml
102+
services:
103+
# ...
104+
105+
App\MyService:
106+
arguments:
107+
$storage: @flysystem.adapter.default.storage
108+
```
95109

96110
Once you have a FilesystemOperator, you can call methods from the
97111
[Filesystem API](https://flysystem.thephpleague.com/v2/docs/usage/filesystem-api/)
98112
to interact with your storage.
99113

100114
## Full documentation
101115

102-
1. [Getting started](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/1-getting-started.md)
116+
1. [Getting started](docs/1-getting-started.md)
103117
2. Cloud storage providers:
104-
[AsyncAws S3](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#asyncaws-s3),
105-
[AWS SDK S3](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#aws-sdk-s3),
106-
[Azure](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#azure),
107-
[Google Cloud Storage](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#google-cloud-storage),
108-
[DigitalOcean Spaces](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#digitalocean-spaces),
109-
[Scaleway Object Storage](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#scaleway-object-storage)
110-
3. [Interacting with FTP and SFTP servers](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/3-interacting-with-ftp-and-sftp-servers.md)
111-
4. [Using a lazy adapter to switch storage backend using an environment variable](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/4-using-lazy-adapter-to-switch-at-runtime.md)
112-
5. [Creating a custom adapter](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/5-creating-a-custom-adapter.md)
113-
6. [MongoDB GridFS](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/6-gridfs.md)
114-
7. [WebDAV](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/7-webdav.md)
115-
8. [BunnyCDN](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/8-bunnycdn.md)
116-
117-
* [Security issue disclosure procedure](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/A-security-disclosure-procedure.md)
118-
* [Configuration reference](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/B-configuration-reference.md)
118+
[AsyncAws S3](docs/2-cloud-storage-providers.md#asyncaws-s3),
119+
[AWS SDK S3](docs/2-cloud-storage-providers.md#aws-sdk-s3),
120+
[Azure](docs/2-cloud-storage-providers.md#azure),
121+
[Google Cloud Storage](docs/2-cloud-storage-providers.md#google-cloud-storage),
122+
[DigitalOcean Spaces](docs/2-cloud-storage-providers.md#digitalocean-spaces),
123+
[Scaleway Object Storage](docs/2-cloud-storage-providers.md#scaleway-object-storage)
124+
3. [Interacting with FTP and SFTP servers](docs/3-interacting-with-ftp-and-sftp-servers.md)
125+
4. [Using a lazy adapter to switch storage backend using an environment variable](docs/4-using-lazy-adapter-to-switch-at-runtime.md)
126+
5. [Creating a custom adapter](docs/5-creating-a-custom-adapter.md)
127+
6. [MongoDB GridFS](docs/6-gridfs.md)
128+
7. [WebDAV](docs/7-webdav.md)
129+
8. [BunnyCDN](docs/8-bunnycdn.md)
130+
131+
* [Security issue disclosure procedure](docs/A-security-disclosure-procedure.md)
132+
* [Configuration reference](docs/B-configuration-reference.md)
119133

120134
## Security Issues
121135

122136
If you discover a security vulnerability within the bundle, please follow
123-
[our disclosure procedure](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/A-security-disclosure-procedure.md).
137+
[our disclosure procedure](docs/A-security-disclosure-procedure.md).
124138

125139
## Backward Compatibility promise
126140

0 commit comments

Comments
 (0)