2017 © Pedro Peláez
 

yii2-extension yii2-flysystem-component

The League Flysystem integration for Yii Framework

image

2amigos/yii2-flysystem-component

The League Flysystem integration for Yii Framework

  • Wednesday, July 19, 2017
  • by tonydspaniard
  • Repository
  • 4 Watchers
  • 8 Stars
  • 694 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 3 Open issues
  • 4 Versions
  • 101 % Grown

The README.md

Flysystem Component Wrappers for Yii 2

Latest Stable Version Software License Build Status Quality Score Total Downloads, (*1)

Flysystem is a file system abstraction which allows you to easily swap out a local filesystem for a remote one., (*2)

This component library provides components that expose the Flysystem API to your Yii 2 applications. The following are the currently supported ones:, (*3)

Install

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

$ composer require 2amigos/yii2-flysystem-component

or add, (*6)

"2amigos/yii2-flysystem-component": "^1.0"

to the require section of your composer.json file., (*7)

Usage

AwsS3FsComponent

Install dependency, (*8)

$ composer require league/flysystem-aws-s3-v3

Configure on the application components section:, (*9)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\AwsS3FsComponent',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'bucket' => 'your-bucket',
            'region' => 'your-region',
            // 'version' => 'latest',
            // 'baseUrl' => 'your-base-url',
            // 'prefix' => 'your-prefix',
            // 'options' => [],
        ],
    ],
];

When you application run, you will be able to use the component as:, (*10)

Yii::$app->fs->read(....);

Check http://flysystem.thephpleague.com/api/ for all the methods available. Same methods for all adapters., (*11)

AzureFsComponent

First ensure the pear repository is added to your composer.json file:, (*12)

"repositories": [
    {
        "type": "pear",
        "url": "http://pear.php.net"
    }
],

Then install the latest version of the plugin, (*13)

$ composer require league/flysystem-azure

Configure on the application components section:, (*14)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\AzureFsComponent',
            'accountName' => 'your-account-name',
            'accountKey' => 'your-account-key',
            'container' => 'your-container',
        ],
    ],
];

DropboxFsComponent

Install dependency, (*15)

$ composer require spatie/flysystem-dropbox

Configure on the application components section:, (*16)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\DropboxFsComponent',
            'token' => 'your-access-token',
            // 'prefix' => 'your-prefix',
        ],
    ],
];

FtpFsComponent

Configure application components as follows, (*17)

return [
    //...
    'components' => [
        //...
        'ftpFs' => [
            'class' => 'dosamigos\flysystem\FtpFsComponent',
            'host' => 'ftp.example.com',
            // 'port' => 21,
            // 'username' => 'your-username',
            // 'password' => 'your-password',
            // 'ssl' => true,
            // 'timeout' => 60,
            // 'root' => '/path/to/root',
            // 'permPrivate' => 0700,
            // 'permPublic' => 0744,
            // 'passive' => false,
            // 'transferMode' => FTP_TEXT,
        ],
    ],
];

GoogleCloudFsComponent

Install dependency, (*18)

$ composer require cedricziel/flysystem-gcs

Configure on the application components section:, (*19)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\GoogleCloudFsComponent',
            'projectId' => 'your-project-id',
            'bucket' => 'your-bucket',
            // 'prefix' => 'your-prefix',
        ],
    ],
];

GridFSFsComponent

Install dependency, (*20)

$ composer require league/flysystem-gridfs

Configure on the application components section:, (*21)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\GridFSFsComponent',
            'server' => 'mongodb://localhost:27017',
            'database' => 'your-database',
        ],
    ],
];

LocalFsComponent

Configure application components as follows, (*22)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\LocalFsComponent',
            'path' => '@webroot/your-writable-folder-to-save-files',
        ],
    ],
];

MemoryFsComponent

Install dependency, (*23)

$ composer require league/flysystem-memory

Configure application components as follows, (*24)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\MemoryFsComponent',
        ],
    ],
];

NullFsComponent

Configure application components as follows, (*25)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\NullFsComponent',
        ],
    ],
];

RackspaceFsComponent

Install dependency, (*26)

$ composer require league/flysystem-rackspace

Configure application components as follows, (*27)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\RackspaceFsComponent',
            'endpoint' => 'your-endpoint',
            'region' => 'your-region',
            'username' => 'your-username',
            'apiKey' => 'your-api-key',
            'container' => 'your-container',
            // 'prefix' => 'your-prefix',
        ],
    ],
];

SftpFsComponent

Install dependency, (*28)

$ composer require league/flysystem-sftp

Configure application components as follows, (*29)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\SftpFsComponent',
            'host' => 'sftp.example.com',
            'username' => 'your-username',
            'password' => 'your-password',
            'privateKey' => '/path/to/or/contents/of/privatekey',
            // 'port' => 22,
            // 'timeout' => 60,
            // 'root' => '/path/to/root',
            // 'permPrivate' => 0700,
            // 'permPublic' => 0744,
        ],
    ],
];

WebDAVFsComponent

Install dependency, (*30)

$ composer require league/flysystem-webdav

Configure application components as follows, (*31)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\WebDAVFsComponent',
            'baseUri' => 'your-base-uri',
            // 'userName' => 'your-user-name',
            // 'password' => 'your-password',
            // 'proxy' => 'your-proxy',
            // 'authType' => \Sabre\DAV\Client::AUTH_BASIC,
            // 'encoding' => \Sabre\DAV\Client::ENCODING_IDENTITY,
            // 'prefix' => 'your-prefix',
        ],
    ],
];

ZipArchiveFsComponent

Install dependency, (*32)

$ composer require league/flysystem-ziparchive

Configure application components as follows, (*33)

return [
    //...
    'components' => [
        //...
        'fs' => [
            'class' => 'dosamigos\flysystem\ZipArchiveFsComponent',
            'path' => '@webroot/files/archive.zip',
            // 'prefix' => 'your-prefix',
        ],
    ],
];

Cool Stuff

Multiple Instances

You can configure as many components as you need. Simply add them to the components section with different names. For example, I could have S3 and FTP at the same time:, (*34)

return [
    //...
    'components' => [
        //...
        's3Fs' => [
            'class' => 'dosamigos\flysystem\AwsS3FsComponent',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'bucket' => 'your-bucket',
            'region' => 'your-region',
            // 'version' => 'latest',
            // 'baseUrl' => 'your-base-url',
            // 'prefix' => 'your-prefix',
            // 'options' => [],
        ],
        'ftpFs => [
            'class' => 'dosamigos\flysystem\FtpFsComponent',
            'host' => 'ftp.example.com',
        ]
    ],
];

Now, I could use them like Yii::$app->s3Fs and Yii::$app->ftpFs respectively., (*35)

Caching

If you wish to add caching functionality, first we need to include the dependencies on your composer.json file:, (*36)

$ composer require league/flysystem-cached-adapter

Next, configure the following attributes on your adapter:, (*37)

return [
 //...
 'components' => [
     //...
     'fs' => [
         //...
         'cache' => 'cacheID',
         // 'cacheKey' => 'my-cache-key',
         // 'cacheDuration' => 7200,
     ],
 ],
];

Replicating

The replication facilitates transitions between adapters, allowing an application to stay functional and migrate its files from one adapter to another. The adapter takes two other adapters, a source and a replica. Every change is delegated to both adapters, while all the read operations are passed onto the source only., (*38)

To use the replication feature first install its dependencies:, (*39)

$ composer require league/flysystem-replicate-adapter

Next, configure as follows:, (*40)

return [
    //...
    'components' => [
        //...
        's3Fs' => [
            'class' => 'dosamigos\flysystem\AwsS3FsComponent',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'bucket' => 'your-bucket',
            'region' => 'your-region',
        ],
        'ftpFs => [
            'class' => 'dosamigos\flysystem\FtpFsComponent',
            'host' => 'ftp.example.com',
            'replica' => 's3Fs' // we have added the ID of the replica component
        ]
    ],
];

Further Information

Testing

$ phpunit

Using code fixer

We have added a PHP code fixer to standardize our code. It includes Symfony, PSR2 and some contributors rules., (*41)

./vendor/bin/php-cs-fixer fix ./src --config .php_cs

Contributing

Please see CONTRIBUTING for details., (*42)

Credits

License

The BSD License (BSD). Please see License File for more information., (*43)


Custom Software | Web & Mobile Software Development
www.2amigos.us

The Versions