Skip to content

Commit e35523f

Browse files
committed
Reinstate Azure Blob Storage support
1 parent 77a3dfb commit e35523f

11 files changed

Lines changed: 172 additions & 2 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ to interact with your storage.
100100
2. Cloud storage providers:
101101
[AsyncAws S3](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#asyncaws-s3),
102102
[AWS SDK S3](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#aws-sdk-s3),
103+
[Azure](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#azure),
103104
[Google Cloud Storage](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#google-cloud-storage),
104105
[DigitalOcean Spaces](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#digitalocean-spaces),
105106
[Scaleway Object Storage](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/2-cloud-storage-providers.md#scaleway-object-storage)

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"require-dev": {
3232
"league/flysystem-async-aws-s3": "^2.0|^3.0",
3333
"league/flysystem-aws-s3-v3": "^2.0|^3.0",
34+
"league/flysystem-azure-blob-storage": "^3.0.5",
3435
"league/flysystem-ftp": "^2.0|^3.0",
3536
"league/flysystem-google-cloud-storage": "^2.0|^3.0",
3637
"league/flysystem-memory": "^2.0|^3.0",

docs/2-cloud-storage-providers.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,36 @@ One of the core feature of Flysystem is its ability to interact easily with remo
44
including many cloud storage providers. This bundle provides the same level of support for these
55
cloud providers by providing corresponding adapters in the configuration.
66

7+
* [Azure](#azure)
78
* [AsyncAws S3](#asyncaws-s3)
89
* [AWS S3](#aws-sdk-s3)
910
* [DigitalOcean Spaces](#digitalocean-spaces)
1011
* [Scaleway Object Storage](#scaleway-object-storage)
1112
* [Google Cloud Storage](#google-cloud-storage)
1213

14+
## Azure
15+
16+
### Installation
17+
18+
```
19+
composer require league/flysystem-azure-blob-storage
20+
```
21+
22+
### Usage
23+
24+
```yaml
25+
# config/packages/flysystem.yaml
26+
27+
flysystem:
28+
storages:
29+
users.storage:
30+
adapter: 'azure'
31+
options:
32+
client: 'azure_client_service' # The service ID of the MicrosoftAzure\Storage\Blob\BlobRestProxy instance
33+
container: 'container_name'
34+
prefix: 'optional/path/prefix'
35+
```
36+
1337
## AsyncAws S3
1438
1539
### Installation

docs/B-configuration-reference.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ flysystem:
99
client: 'aws_client_service'
1010
bucket: 'bucket_name'
1111
prefix: 'optional/path/prefix'
12-
12+
1313
users2.storage:
14-
adapter: 'custom_adapter'
14+
adapter: 'azure'
15+
options:
16+
client: 'azure_client_service'
17+
container: 'container_name'
18+
prefix: 'optional/path/prefix'
1519

1620
users3.storage:
1721
adapter: 'ftp'
@@ -72,4 +76,6 @@ flysystem:
7276
options:
7377
source: 'flysystem_storage_service_to_use'
7478

79+
users10.storage:
80+
adapter: 'custom_adapter'
7581
```

src/Adapter/AdapterDefinitionFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct()
3131
$this->builders = [
3232
new Builder\AsyncAwsAdapterDefinitionBuilder(),
3333
new Builder\AwsAdapterDefinitionBuilder(),
34+
new Builder\AzureAdapterDefinitionBuilder(),
3435
new Builder\FtpAdapterDefinitionBuilder(),
3536
new Builder\GcloudAdapterDefinitionBuilder(),
3637
new Builder\LocalAdapterDefinitionBuilder(),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <galopintitouan@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace League\FlysystemBundle\Adapter\Builder;
13+
14+
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Titouan Galopin <galopintitouan@gmail.com>
21+
*
22+
* @internal
23+
*/
24+
class AzureAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
25+
{
26+
public function getName(): string
27+
{
28+
return 'azure';
29+
}
30+
31+
protected function getRequiredPackages(): array
32+
{
33+
return [
34+
AzureBlobStorageAdapter::class => 'league/flysystem-azure-blob-storage',
35+
];
36+
}
37+
38+
protected function configureOptions(OptionsResolver $resolver)
39+
{
40+
$resolver->setRequired('client');
41+
$resolver->setAllowedTypes('client', 'string');
42+
43+
$resolver->setRequired('container');
44+
$resolver->setAllowedTypes('container', 'string');
45+
46+
$resolver->setDefault('prefix', '');
47+
$resolver->setAllowedTypes('prefix', 'string');
48+
}
49+
50+
protected function configureDefinition(Definition $definition, array $options)
51+
{
52+
$definition->setClass(AzureBlobStorageAdapter::class);
53+
$definition->setArgument(0, new Reference($options['client']));
54+
$definition->setArgument(1, $options['container']);
55+
$definition->setArgument(2, $options['prefix']);
56+
}
57+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <galopintitouan@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\League\FlysystemBundle\Adapter\Builder;
13+
14+
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
15+
use League\FlysystemBundle\Adapter\Builder\AzureAdapterDefinitionBuilder;
16+
use PHPUnit\Framework\TestCase;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
19+
class AzureAdapterDefinitionBuilderTest extends TestCase
20+
{
21+
public function createBuilder()
22+
{
23+
return new AzureAdapterDefinitionBuilder();
24+
}
25+
26+
public function provideValidOptions()
27+
{
28+
yield 'minimal' => [[
29+
'client' => 'my_client',
30+
'container' => 'container_name',
31+
]];
32+
33+
yield 'prefix' => [[
34+
'client' => 'my_client',
35+
'container' => 'container_name',
36+
'prefix' => 'prefix/path',
37+
]];
38+
}
39+
40+
/**
41+
* @dataProvider provideValidOptions
42+
*/
43+
public function testCreateDefinition($options)
44+
{
45+
$this->assertSame(AzureBlobStorageAdapter::class, $this->createBuilder()->createDefinition($options)->getClass());
46+
}
47+
48+
public function testOptionsBehavior()
49+
{
50+
$definition = $this->createBuilder()->createDefinition([
51+
'client' => 'my_client',
52+
'container' => 'container_name',
53+
'prefix' => 'prefix/path',
54+
]);
55+
56+
$this->assertSame(AzureBlobStorageAdapter::class, $definition->getClass());
57+
$this->assertInstanceOf(Reference::class, $definition->getArgument(0));
58+
$this->assertSame('my_client', (string) $definition->getArgument(0));
59+
$this->assertSame('container_name', $definition->getArgument(1));
60+
$this->assertSame('prefix/path', $definition->getArgument(2));
61+
}
62+
}

tests/Adapter/options.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ fs_aws:
1212
bucket: 'bucket_name'
1313
prefix: 'optional/path/prefix'
1414

15+
fs_azure:
16+
adapter: 'azure'
17+
options:
18+
client: 'azure_client_service'
19+
container: 'container_name'
20+
prefix: 'optional/path/prefix'
21+
1522
fs_ftp:
1623
adapter: 'ftp'
1724
options:

tests/DependencyInjection/FlysystemExtensionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Google\Cloud\Storage\Bucket;
1717
use Google\Cloud\Storage\StorageClient;
1818
use League\Flysystem\FilesystemOperator;
19+
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
1920
use PHPUnit\Framework\TestCase;
2021
use Symfony\Component\Dotenv\Dotenv;
2122
use Tests\League\FlysystemBundle\Kernel\FlysystemAppKernel;
@@ -26,6 +27,7 @@ public function provideFilesystems()
2627
{
2728
$fsNames = [
2829
'fs_aws',
30+
'fs_azure',
2931
'fs_custom',
3032
'fs_ftp',
3133
'fs_gcloud',
@@ -99,6 +101,7 @@ private function getClientMocks()
99101
return [
100102
'aws_client_service' => $this->createMock(S3Client::class),
101103
'asyncaws_client_service' => $this->createMock(AsyncS3Client::class),
104+
'azure_client_service' => $this->createMock(BlobRestProxy::class),
102105
'gcloud_client_service' => $gcloud,
103106
];
104107
}

tests/Kernel/config/flysystem.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ flysystem:
1414
bucket: '%env(AWS_BUCKET)%'
1515
prefix: 'optional/path/prefix'
1616

17+
fs_azure:
18+
adapter: 'azure'
19+
options:
20+
client: 'azure_client_service'
21+
container: 'container_name'
22+
prefix: 'optional/path/prefix'
23+
1724
fs_custom:
1825
adapter: 'custom_adapter'
1926

0 commit comments

Comments
 (0)