From b5f0caa9ee098e878158a46e48cfdc81bcb8bcf9 Mon Sep 17 00:00:00 2001 From: David Greminger Date: Tue, 15 Oct 2024 08:48:15 +0200 Subject: [PATCH] Use a visibility converter service instead of a string (#309) --- doc/adapter_async_aws_s3.md | 2 +- doc/adapter_awss3.md | 4 ++++ doc/adapter_ftp.md | 4 ++++ src/DependencyInjection/Factory/Adapter/AwsS3V3Factory.php | 4 +++- src/DependencyInjection/Factory/Adapter/FtpFactory.php | 5 ++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/adapter_async_aws_s3.md b/doc/adapter_async_aws_s3.md index f8c31a7..404edfb 100644 --- a/doc/adapter_async_aws_s3.md +++ b/doc/adapter_async_aws_s3.md @@ -8,7 +8,7 @@ the S3 client at [async-aws.com](https://async-aws.com/clients/) or use the ```yml services: acme.async.portable_visibility_converter: - class: League\Flysystem\AsyncAwsS3\PortableVisibilityConverter: + class: League\Flysystem\AsyncAwsS3\PortableVisibilityConverter acme.async_s3_client: class: AsyncAws\S3\S3Client diff --git a/doc/adapter_awss3.md b/doc/adapter_awss3.md index 0971307..0d2b105 100644 --- a/doc/adapter_awss3.md +++ b/doc/adapter_awss3.md @@ -11,6 +11,9 @@ This version requires you to use the "v4" of the signature. ```yml services: + acme.awss3v3.portable_visibility_converter: + class: League\Flysystem\AwsS3V3\PortableVisibilityConverter + acme.s3_client: class: Aws\S3\S3Client arguments: @@ -32,6 +35,7 @@ oneup_flysystem: client: acme.s3_client bucket: 'bucket-name' prefix: 'path/prefix' # Optional path prefix, you can set empty string + visibilityConverter: acme.awss3v3.portable_visibility_converter ``` For more details on the other parameters, take a look at the [Flysystem documentation](https://flysystem.thephpleague.com/v2/docs/adapter/aws-s3-v3/). diff --git a/doc/adapter_ftp.md b/doc/adapter_ftp.md index 016e605..bef5758 100644 --- a/doc/adapter_ftp.md +++ b/doc/adapter_ftp.md @@ -6,6 +6,9 @@ You have to provide at least a value for the `host` key. ```yml # app/config/config.yml oneup_flysystem: + acme.ftp.portable_visibility_converter: + class: League\Flysystem\UnixVisibility\PortableVisibilityConverter + adapters: my_adapter: ftp: @@ -14,6 +17,7 @@ oneup_flysystem: root: '/upload' # required username: 'username' # required password: 'password' # required + visibilityConverter: acme.ftp.portable_visibility_converter ``` For more details on the other parameters, take a look at the [Flysystem documentation](https://flysystem.thephpleague.com/v2/docs/adapter/ftp/). diff --git a/src/DependencyInjection/Factory/Adapter/AwsS3V3Factory.php b/src/DependencyInjection/Factory/Adapter/AwsS3V3Factory.php index 1eb27b6..099fea1 100644 --- a/src/DependencyInjection/Factory/Adapter/AwsS3V3Factory.php +++ b/src/DependencyInjection/Factory/Adapter/AwsS3V3Factory.php @@ -19,12 +19,14 @@ public function getKey(): string public function create(ContainerBuilder $container, string $id, array $config): void { + $visibilityConverter = $config['visibilityConverter'] ? new Reference($config['visibilityConverter']) : null; + $container ->setDefinition($id, new ChildDefinition('oneup_flysystem.adapter.awss3v3')) ->replaceArgument(0, new Reference($config['client'])) ->replaceArgument(1, $config['bucket']) ->replaceArgument(2, $config['prefix']) - ->replaceArgument(3, $config['visibilityConverter']) + ->replaceArgument(3, $visibilityConverter) ->replaceArgument(4, $config['mimeTypeDetector']) ->replaceArgument(5, (array) $config['options']) ->replaceArgument(6, $config['streamReads']) diff --git a/src/DependencyInjection/Factory/Adapter/FtpFactory.php b/src/DependencyInjection/Factory/Adapter/FtpFactory.php index ab9bb18..8c91e24 100644 --- a/src/DependencyInjection/Factory/Adapter/FtpFactory.php +++ b/src/DependencyInjection/Factory/Adapter/FtpFactory.php @@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; class FtpFactory implements AdapterFactoryInterface { @@ -20,6 +21,8 @@ public function getKey(): string public function create(ContainerBuilder $container, string $id, array $config): void { + $visibilityConverter = $config['visibilityConverter'] ? new Reference($config['visibilityConverter']) : null; + $container ->setDefinition($id, new ChildDefinition('oneup_flysystem.adapter.ftp')) ->replaceArgument(0, @@ -30,7 +33,7 @@ public function create(ContainerBuilder $container, string $id, array $config): ) ->replaceArgument(1, $config['connectionProvider']) ->replaceArgument(2, $config['connectivityChecker']) - ->replaceArgument(3, $config['visibilityConverter']) + ->replaceArgument(3, $visibilityConverter) ->replaceArgument(4, $config['mimeTypeDetector']) ; }