From 33bb1234e1e4f31ee4e6d1ef22020012e0efd6c1 Mon Sep 17 00:00:00 2001 From: developernurullah <117896864+developernurullah@users.noreply.github.com> Date: Thu, 1 Dec 2022 18:17:22 +0530 Subject: [PATCH] Add Azure Blob Storage adapter (#271) Co-authored-by: MD Nurullah Co-authored-by: David Greminger --- .github/workflows/ci.yml | 10 ++--- README.md | 1 + composer.json | 3 +- doc/adapter_azure_blob_storage.md | 20 ++++++++++ doc/index.md | 2 + .../Factory/Adapter/AzureBlobFactory.php | 40 +++++++++++++++++++ .../Factory/Adapter/LocalFactory.php | 2 +- src/Resources/config/adapters.xml | 5 +++ src/Resources/config/factories.xml | 4 ++ 9 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 doc/adapter_azure_blob_storage.md create mode 100644 src/DependencyInjection/Factory/Adapter/AzureBlobFactory.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94de90a..685446f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@2.7.0 with: - php-version: 7.4 + php-version: 8.0 extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib coverage: none @@ -36,12 +36,8 @@ jobs: strategy: fail-fast: false matrix: - php: [7.4, 8.0, 8.1] + php: [8.0, 8.1] symfony: [4.4, 5.4, 6.0] - exclude: - # Symfony 6.0 does not supports php <8.0 - - php: 7.4 - symfony: 6.0 steps: - name: Setup PHP uses: shivammathur/setup-php@2.7.0 @@ -67,7 +63,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@2.7.0 with: - php-version: 7.4 + php-version: 8.0 extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib coverage: none diff --git a/README.md b/README.md index c8d55c4..77fae61 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ The OneupFlysystemBundle provides a [Flysystem](https://github.com/thephpleague/ * [Google Cloud Storage](https://cloud.google.com/storage) * [AsyncAwsS3](https://async-aws.com/) * [AwsS3](http://aws.amazon.com/de/sdkforphp/) +* [AzureBlobStorage](https://azure.microsoft.com/en-us/services/storage/blobs/) * [Ftp](http://php.net/manual/en/book.ftp.php) * [Local filesystem](http://php.net/manual/en/ref.filesystem.php) * [Sftp](http://phpseclib.sourceforge.net/sftp/intro.html) diff --git a/composer.json b/composer.json index 4688803..a201af3 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "league/flysystem": "^2.0 || ^3.0", "symfony/config": "^4.4 || ^5.3 || ^6.0", "symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0", @@ -40,6 +40,7 @@ "league/flysystem-google-cloud-storage": "^2.0 || ^3.0", "league/flysystem-memory": "^2.0 || ^3.0", "league/flysystem-sftp": "^2.0 || ^3.0", + "league/flysystem-azure-blob-storage": "^3.0", "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^9.5", "royvoetman/flysystem-gitlab-storage": "^2.0 || ^3.0", diff --git a/doc/adapter_azure_blob_storage.md b/doc/adapter_azure_blob_storage.md new file mode 100644 index 0000000..5315546 --- /dev/null +++ b/doc/adapter_azure_blob_storage.md @@ -0,0 +1,20 @@ +# Use the Azure Blob Storage adapter + +This adapter connects to the filesystem in the Azure Blob Storage. + + +```yml +oneup_flysystem: + adapters: + acme.flysystem_adapter: + azureblob: + client: 'azure_blob_storage_client' # Service ID of the MicrosoftAzure\Storage\Blob\BlobRestProxy + container: 'container-name' + prefix: 'optional/prefix' +``` + +For more details on the other parameters, take a look at the [Flysystem documentation](https://flysystem.thephpleague.com/docs/adapter/azure-blob-storage/). + +## More to know + +* [Create and use your filesystem](filesystem_create.md) diff --git a/doc/index.md b/doc/index.md index f1b787b..9e8b389 100644 --- a/doc/index.md +++ b/doc/index.md @@ -28,6 +28,7 @@ Composer will now fetch and install this bundle in the vendor directory `vendor/ * The InMemory adapter requires `"league/flysystem-memory"` * The AsyncAwsS3 adapter requires `"league/flysystem-async-aws-s3"` * The Gitlab adapter requires `"royvoetman/flysystem-gitlab-storage"` +* The Azure Blob Storage adapter requires `"league/flysystem-azure-blob-storage"` ### Step 2: Enable the bundle Enable the bundle in the kernel: @@ -78,6 +79,7 @@ There are a bunch of adapters for you to use: * [InMemoryAdapter](adapter_in_memory.md) * [Sftp](adapter_sftp.md) * [Gitlab](adapter_gitlab.md) +* [AzureBlobStorage](adapter_azure_blob_storage.md) * [Custom](adapter_custom.md) ### Step 4: Next steps diff --git a/src/DependencyInjection/Factory/Adapter/AzureBlobFactory.php b/src/DependencyInjection/Factory/Adapter/AzureBlobFactory.php new file mode 100644 index 0000000..a07f5b4 --- /dev/null +++ b/src/DependencyInjection/Factory/Adapter/AzureBlobFactory.php @@ -0,0 +1,40 @@ +setDefinition($id, new ChildDefinition('oneup_flysystem.adapter.azureblob')) + ->replaceArgument(0, new Reference($config['client'])) + ->replaceArgument(1, $config['container']) + ->replaceArgument(2, $config['prefix']) + ; + } + + public function addConfiguration(NodeDefinition $node): void + { + $node + ->children() + ->scalarNode('client')->isRequired()->end() + ->scalarNode('container')->isRequired()->end() + ->scalarNode('prefix')->defaultNull()->end() + ->end() + ; + } +} diff --git a/src/DependencyInjection/Factory/Adapter/LocalFactory.php b/src/DependencyInjection/Factory/Adapter/LocalFactory.php index fe03133..79b9d71 100644 --- a/src/DependencyInjection/Factory/Adapter/LocalFactory.php +++ b/src/DependencyInjection/Factory/Adapter/LocalFactory.php @@ -26,7 +26,7 @@ public function create(ContainerBuilder $container, string $id, array $config): if (isset($config['permissions']) && null !== $config['permissions']) { $visibilityConverter = new Definition(PortableVisibilityConverter::class); $visibilityConverter->setFactory([PortableVisibilityConverter::class, 'fromArray']); - $visibilityConverter->setArgument(0, $config['permissions'] ?? []); + $visibilityConverter->setArgument(0, $config['permissions']); } $container diff --git a/src/Resources/config/adapters.xml b/src/Resources/config/adapters.xml index 8b6d473..3a7f304 100644 --- a/src/Resources/config/adapters.xml +++ b/src/Resources/config/adapters.xml @@ -53,5 +53,10 @@ + + + + + diff --git a/src/Resources/config/factories.xml b/src/Resources/config/factories.xml index 01923a4..e58603f 100644 --- a/src/Resources/config/factories.xml +++ b/src/Resources/config/factories.xml @@ -40,5 +40,9 @@ class="Oneup\FlysystemBundle\DependencyInjection\Factory\Adapter\GitlabFactory"> + + +