storage config simplified

This commit is contained in:
Milos Stojanovic
2019-06-19 09:36:45 +02:00
parent 5da41e63c9
commit 0eaa8184c4
6 changed files with 59 additions and 90 deletions

View File

@@ -26,7 +26,7 @@ class Filesystem implements Service
$this->separator = $config['separator']; $this->separator = $config['separator'];
$this->path_prefix = $this->separator; $this->path_prefix = $this->separator;
$adapter = $config['adapters'][$config['filesystem_adapter']]; $adapter = $config['adapter'];
$config = isset($config['config']) ? $config['config'] : []; $config = isset($config['config']) ? $config['config'] : [];
$this->storage = new Flysystem($adapter(), $config); $this->storage = new Flysystem($adapter(), $config);

View File

@@ -75,14 +75,11 @@ return [
'config' => [ 'config' => [
'separator' => '/', 'separator' => '/',
'config' => [], 'config' => [],
'filesystem_adapter' => 'localfilesystem', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Adapter\Local(
'localfilesystem' => function () { __DIR__.'/repository'
return new \League\Flysystem\Adapter\Local( );
__DIR__.'/repository' },
);
},
],
], ],
], ],
'Filegator\Services\Archiver\ArchiverInterface' => [ 'Filegator\Services\Archiver\ArchiverInterface' => [

View File

@@ -14,14 +14,11 @@ With default adapter you just need to configure where your ```repository``` fold
'config' => [ 'config' => [
'separator' => '/', 'separator' => '/',
'config' => [], 'config' => [],
'filesystem_adapter' => 'localfilesystem', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Adapter\Local(
'localfilesystem' => function () { __DIR__.'/repository'
return new \League\Flysystem\Adapter\Local( );
__DIR__.'/repository' },
);
},
],
], ],
], ],
@@ -36,18 +33,15 @@ See official [documentation](https://flysystem.thephpleague.com/docs/adapter/ftp
'config' => [ 'config' => [
'separator' => '/', 'separator' => '/',
'config' => [], 'config' => [],
'filesystem_adapter' => 'ftp', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Adapter\Ftp([
'ftp' => function () { 'host' => 'example.com',
return new \League\Flysystem\Adapter\Ftp([ 'username' => 'demo',
'host' => 'example.com', 'password' => 'password',
'username' => 'demo', 'port' => 21,
'password' => 'password', 'timeout' => 10,
'port' => 21, ]);
'timeout' => 10, },
]);
},
],
], ],
], ],
@@ -64,18 +58,15 @@ See official [documentation](https://flysystem.thephpleague.com/docs/adapter/sft
'config' => [ 'config' => [
'separator' => '/', 'separator' => '/',
'config' => [], 'config' => [],
'filesystem_adapter' => 'sftp', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Sftp\SftpAdapter([
'sftp' => function () { 'host' => 'example.com',
return new \League\Flysystem\Sftp\SftpAdapter([ 'port' => 22,
'host' => 'example.com', 'username' => 'demo',
'port' => 22, 'password' => 'password',
'username' => 'demo', 'timeout' => 10,
'password' => 'password', ]);
'timeout' => 10, },
]);
},
],
], ],
], ],
@@ -90,16 +81,15 @@ See official [documentation](https://flysystem.thephpleague.com/docs/adapter/dro
'handler' => '\Filegator\Services\Storage\Filesystem', 'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [ 'config' => [
'separator' => '/', 'separator' => '/',
'config' => [], 'config' => [
'filesystem_adapter' => 'dropbox', 'case_sensitive' => false,
'adapters' => [
'dropbox' => function () {
$authorizationToken = '1234';
$client = new \Spatie\Dropbox\Client($authorizationToken);
return new \Spatie\FlysystemDropbox\DropboxAdapter($client);
},
], ],
'adapter' => function () {
$authorizationToken = '1234';
$client = new \Spatie\Dropbox\Client($authorizationToken);
return new \Spatie\FlysystemDropbox\DropboxAdapter($client);
},
], ],
], ],

View File

@@ -41,12 +41,9 @@ class ArchiverTest extends TestCase
$storage = new Filesystem(); $storage = new Filesystem();
$storage->init([ $storage->init([
'separator' => '/', 'separator' => '/',
'filesystem_adapter' => 'nulladapter', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Adapter\NullAdapter();
'nulladapter' => function () { },
return new \League\Flysystem\Adapter\NullAdapter();
},
],
]); ]);
$uniqid = $this->archiver->createArchive($storage); $uniqid = $this->archiver->createArchive($storage);
@@ -60,12 +57,9 @@ class ArchiverTest extends TestCase
$storage = new Filesystem(); $storage = new Filesystem();
$storage->init([ $storage->init([
'separator' => '/', 'separator' => '/',
'filesystem_adapter' => 'memoryadapter', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Memory\MemoryAdapter();
'memoryadapter' => function () { },
return new \League\Flysystem\Memory\MemoryAdapter();
},
],
]); ]);
$storage->createDir('/', 'test'); $storage->createDir('/', 'test');
@@ -85,12 +79,9 @@ class ArchiverTest extends TestCase
$storage = new Filesystem(); $storage = new Filesystem();
$storage->init([ $storage->init([
'separator' => '/', 'separator' => '/',
'filesystem_adapter' => 'memoryadapter', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Memory\MemoryAdapter();
'memoryadapter' => function () { },
return new \League\Flysystem\Memory\MemoryAdapter();
},
],
]); ]);
$storage->createDir('/', 'test'); $storage->createDir('/', 'test');
@@ -110,12 +101,9 @@ class ArchiverTest extends TestCase
$storage = new Filesystem(); $storage = new Filesystem();
$storage->init([ $storage->init([
'separator' => '/', 'separator' => '/',
'filesystem_adapter' => 'memoryadapter', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Memory\MemoryAdapter();
'memoryadapter' => function () { },
return new \League\Flysystem\Memory\MemoryAdapter();
},
],
]); ]);
$stream = fopen(TEST_ARCHIVE, 'r'); $stream = fopen(TEST_ARCHIVE, 'r');

View File

@@ -33,14 +33,11 @@ class FilesystemTest extends TestCase
$this->storage = new Filesystem(); $this->storage = new Filesystem();
$this->storage->init([ $this->storage->init([
'separator' => '/', 'separator' => '/',
'filesystem_adapter' => 'localfilesystem', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Adapter\Local(
'localfilesystem' => function () { TEST_REPOSITORY
return new \League\Flysystem\Adapter\Local( );
TEST_REPOSITORY },
);
},
],
]); ]);
} }

View File

@@ -52,14 +52,11 @@ return [
'handler' => '\Filegator\Services\Storage\Filesystem', 'handler' => '\Filegator\Services\Storage\Filesystem',
'config' => [ 'config' => [
'separator' => '/', 'separator' => '/',
'filesystem_adapter' => 'localfilesystem', 'adapter' => function () {
'adapters' => [ return new \League\Flysystem\Adapter\Local(
'localfilesystem' => function () { TEST_REPOSITORY
return new \League\Flysystem\Adapter\Local( );
TEST_REPOSITORY },
);
},
],
], ],
], ],
'Filegator\Services\Auth\AuthInterface' => [ 'Filegator\Services\Auth\AuthInterface' => [