Giter VIP home page Giter VIP logo

flysystem's Introduction

Nette Flysystem

Build Status GitHub license

Integration of Flysystem into Nette Framework including support Flysystem Plugins.

Installation

Via Composer

$ composer require surda/flysystem

and add to config.neon

extensions:
    flysystem:  Surda\Flysystem\Bridges\NetteDI\FlysystemExtension

Minimal configuration for using Filesystem

Example with Local Adapter.

flysystem:
    filesystem:
        adapter: League\Flysystem\Adapter\Local('/path/to/folder')

Usage

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');
    }
}

Minimal configuration for using MountManager

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')
            ...

Usage

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');
    }
}

Adapter arguments

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'

Plugins

Global plugins

Adding plugins to all Filesystems and Mountmanager.

flysystem:
    plugins:
        - League\Flysystem\Plugin\ListFiles()
        - League\Flysystem\Plugin\ListPaths()

Plugins for Filesystems

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()

Plugins for Mountmanager

Adding plugins only to Mountmanager.

flysystem:
    mountmanager:
        plugins:
            - Namespace\MyPlugin5()
            - Namespace\MyPlugin6()

Config argument in Filesystem

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
            ...

flysystem's People

Contributors

surda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.