-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for AsyncAws's Flysystem adapter
- Loading branch information
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the flysystem-bundle project. | ||
* | ||
* (c) Titouan Galopin <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace League\FlysystemBundle\Adapter\Builder; | ||
|
||
use AsyncAws\Flysystem\S3\S3FilesystemV1; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Titouan Galopin <[email protected]> | ||
* @author Tobias Nyholm <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class AsyncAwsAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'asyncaws'; | ||
} | ||
|
||
protected function getRequiredPackages(): array | ||
{ | ||
return [ | ||
S3FilesystemV1::class => 'async-aws/flysystem-s3', | ||
]; | ||
} | ||
|
||
protected function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setRequired('client'); | ||
$resolver->setAllowedTypes('client', 'string'); | ||
|
||
$resolver->setRequired('bucket'); | ||
$resolver->setAllowedTypes('bucket', 'string'); | ||
|
||
$resolver->setDefault('prefix', ''); | ||
$resolver->setAllowedTypes('prefix', 'string'); | ||
|
||
$resolver->setDefault('options', []); | ||
$resolver->setAllowedTypes('options', 'array'); | ||
} | ||
|
||
protected function configureDefinition(Definition $definition, array $options) | ||
{ | ||
$definition->setClass(S3FilesystemV1::class); | ||
$definition->setArgument(0, new Reference($options['client'])); | ||
$definition->setArgument(1, $options['bucket']); | ||
$definition->setArgument(2, $options['prefix']); | ||
$definition->setArgument(3, $options['options']); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
tests/Adapter/Builder/AsyncAwsAdapterDefinitionBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the flysystem-bundle project. | ||
* | ||
* (c) Titouan Galopin <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\League\FlysystemBundle\Adapter\Builder; | ||
|
||
use AsyncAws\Flysystem\S3\S3FilesystemV1; | ||
use League\FlysystemBundle\Adapter\Builder\AsyncAwsAdapterDefinitionBuilder; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class AsyncAwsAdapterDefinitionBuilderTest extends TestCase | ||
{ | ||
public function createBuilder() | ||
{ | ||
return new AsyncAwsAdapterDefinitionBuilder(); | ||
} | ||
|
||
public function provideValidOptions() | ||
{ | ||
yield 'minimal' => [[ | ||
'client' => 'my_client', | ||
'bucket' => 'bucket', | ||
]]; | ||
|
||
yield 'prefix' => [[ | ||
'client' => 'my_client', | ||
'bucket' => 'bucket', | ||
'prefix' => 'prefix/path', | ||
]]; | ||
|
||
yield 'options' => [[ | ||
'client' => 'my_client', | ||
'bucket' => 'bucket', | ||
'options' => [ | ||
'ServerSideEncryption' => 'AES256', | ||
], | ||
]]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideValidOptions | ||
*/ | ||
public function testCreateDefinition($options) | ||
{ | ||
$this->assertSame(S3FilesystemV1::class, $this->createBuilder()->createDefinition($options)->getClass()); | ||
} | ||
|
||
public function testOptionsBehavior() | ||
{ | ||
$definition = $this->createBuilder()->createDefinition([ | ||
'client' => 'my_client', | ||
'bucket' => 'bucket', | ||
'prefix' => 'prefix/path', | ||
'options' => [ | ||
'ServerSideEncryption' => 'AES256', | ||
], | ||
]); | ||
|
||
$this->assertSame(S3FilesystemV1::class, $definition->getClass()); | ||
$this->assertInstanceOf(Reference::class, $definition->getArgument(0)); | ||
$this->assertSame('my_client', (string) $definition->getArgument(0)); | ||
$this->assertSame('bucket', $definition->getArgument(1)); | ||
$this->assertSame('prefix/path', $definition->getArgument(2)); | ||
$this->assertSame(['ServerSideEncryption' => 'AES256'], $definition->getArgument(3)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters