Skip to content

Commit

Permalink
Add support for major release of Azure Blob Storage SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
z38 committed Mar 25, 2018
1 parent d413c69 commit 04e7b3f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"mikey179/vfsStream": "~1.2.0",
"league/flysystem": "~1.0",
"mongodb/mongodb": "^1.1",
"microsoft/windowsazure": "~0.4",
"microsoft/azure-storage": "~0.15.0",
"microsoft/azure-storage-blob": "^1.0",
"akeneo/phpspec-skip-example-extension": "~1.2"
},
"suggest": {
Expand Down
6 changes: 1 addition & 5 deletions doc/adapters/azure-blob-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ currentMenu: azure-blob-storage

# AzureBlobStorage

First, you will need to install the adapter:
Azure Blob Storage is the storage service provided by Microsoft Windows Azure cloud environment. First, you will need to install the adapter:
```bash
composer require gaufrette/azure-blob-storage-adapter
```

Azure Blob Storage is the storage service provided by Microsoft Windows Azure cloud environment. To use this adapter
you need to install the [Azure SDK for php](http://www.windowsazure.com/en-us/develop/php/common-tasks/download-php-sdk/)
into your project.

To instantiate the `AzureBlobStorage` adapter you need a `BlobProxyFactoryInterface` instance (you can use the default
`BlobProxyFactory` class) and a connection string. The connection string should follow this prototype:

Expand Down
8 changes: 7 additions & 1 deletion src/Gaufrette/Adapter/AzureBlobStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MicrosoftAzure\Storage\Blob\Models\Blob;
use MicrosoftAzure\Storage\Blob\Models\Container;
use MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\CreateBlockBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\DeleteContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\ListBlobsOptions;
Expand Down Expand Up @@ -187,7 +188,12 @@ public function write($key, $content)
$this->init();
list($containerName, $key) = $this->tokenizeKey($key);

$options = new CreateBlobOptions();
if (class_exists(CreateBlockBlobOptions::class)) {
$options = new CreateBlockBlobOptions();
} else {
// for microsoft/azure-storage < 1.0
$options = new CreateBlobOptions();
}

if ($this->detectContentType) {
$contentType = $this->guessContentType($content);
Expand Down
8 changes: 7 additions & 1 deletion src/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gaufrette\Adapter\AzureBlobStorage;

use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use MicrosoftAzure\Storage\Common\ServicesBuilder;

/**
Expand Down Expand Up @@ -29,6 +30,11 @@ public function __construct($connectionString)
*/
public function create()
{
return ServicesBuilder::getInstance()->createBlobService($this->connectionString);
if (class_exists(ServicesBuilder::class)) {
// for microsoft/azure-storage < 1.0
return ServicesBuilder::getInstance()->createBlobService($this->connectionString);
} else {
return BlobRestProxy::createBlobService($this->connectionString);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function shouldKeepFileObjectInRegister()
* @test
* @group functional
*/
public function shouldWrtieToSameFile()
public function shouldWriteToSameFile()
{
$path = $this->createUniqueContainerName('container') . '/somefile';

Expand All @@ -223,7 +223,7 @@ public function shouldWrtieToSameFile()
$FileObjectB = $this->filesystem->createFile($path);
$FileObjectB->setContent('DEF');

$this->assertEquals('DEF', $FileObjectB->getContent());
$this->assertEquals('DEF', $FileObjectA->getContent());
}

private function createUniqueContainerName($prefix)
Expand Down
2 changes: 1 addition & 1 deletion tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ public function shouldWriteToSameFile()
$FileObjectB = $this->filesystem->createFile('somefile');
$FileObjectB->setContent('DEF');

$this->assertEquals('DEF', $FileObjectB->getContent());
$this->assertEquals('DEF', $FileObjectA->getContent());
}
}

0 comments on commit 04e7b3f

Please sign in to comment.