Skip to content

Add support for major release of Azure Blob Storage SDK #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}