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->path_prefix = $this->separator;
$adapter = $config['adapters'][$config['filesystem_adapter']];
$adapter = $config['adapter'];
$config = isset($config['config']) ? $config['config'] : [];
$this->storage = new Flysystem($adapter(), $config);

View File

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

View File

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

View File

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

View File

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

View File

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