league/flysystem-bundle

Symfony bundle integrating Flysystem into Symfony 4.2+ applications

Installs: 169 891

Dependents: 5

Suggesters: 1

Security: 0

Stars: 117

Watchers: 4

Forks: 18

Open Issues: 2

Type:symfony-bundle

1.4.0 2019-12-21 13:27 UTC

This package is auto-updated.

Last update: 2020-01-21 14:32:37 UTC


README

Build Status Packagist Version Software license

SymfonyInsight

flysystem-bundle is a Symfony bundle integrating the Flysystem library into Symfony applications.

It provides an efficient abstraction for the filesystem in order to change the storage backend depending on the execution environment (local files in development, cloud storage in production and memory in tests).

Installation

flysystem-bundle requires PHP 7.1+ and Symfony 4.2+.

You can install the bundle using Symfony Flex:

composer require league/flysystem-bundle

Basic usage

The default configuration file created by Symfony Flex provides enough configuration to use Flysystem in your application as soon as you install the bundle:

# config/packages/flysystem.yaml

flysystem:
    storages:
        default.storage:
            adapter: 'local'
            options:
                directory: '%kernel.project_dir%/var/storage/default'

This configuration defines a single storage service (default.storage) based on the local adapter and configured to use the %kernel.project_dir%/var/storage/default directory.

For each storage defined under flysystem.storages, an associated service is created using the name you provide (in this case, a service default.storage will be created). The bundle also creates a named alias for each of these services.

This means you have two way of using the defined storages:

  • either using autowiring, by typehinting against the FilesystemInterface and using the variable name matching one of your storages:

    use League\Flysystem\FilesystemInterface;
    
    class MyService
    {
        private $storage;
        
        // The variable name $defaultStorage matters: it needs to be the camelized version
        // of the name of your storage. 
        public function __construct(FilesystemInterface $defaultStorage)
        {
            $this->storage = $defaultStorage;
        }
        
        // ...
    }

    The same goes for controllers:

    use League\Flysystem\FilesystemInterface;
    
    class MyController
    {
        // The variable name $defaultStorage matters: it needs to be the camelized version
        // of the name of your storage. 
        public function index(FilesystemInterface $defaultStorage)
        {
            // ...
        }
    }
  • or using manual injection, by injecting the service named default.storage inside your services.

Once you have a FilesystemInterface, you can call methods from the Filesystem API to interact with your storage.

Full documentation

  1. Getting started
  2. Cloud storage providers: Azure, AWS S3, DigitalOcean Spaces, Scaleway Object Storage, Google Cloud Storage, Rackspace, WebDAV
  3. Interacting with FTP and SFTP servers
  4. Caching metadata in Symfony cache
  5. Using a lazy adapter to switch storage backend using an environment variable
  6. Creating a custom adapter

Security Issues

If you discover a security vulnerability within the bundle, please follow our disclosure procedure.

Backward Compatibility promise

This library follows the same Backward Compatibility promise as the Symfony framework: https://symfony.com/doc/current/contributing/code/bc.html

Note: many classes in this bundle are either marked @final or @internal. @internal classes are excluded from any Backward Compatiblity promise (you should not use them in your code) whereas @final classes can be used but should not be extended (use composition instead).