From 9a6259ea5e3df02fbb9b395752eaa6a7e302e868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=96zkan?= <1721527+hakan0xFF@users.noreply.github.com> Date: Mon, 22 Jul 2019 11:35:42 +0200 Subject: [PATCH] feat: support custom prefix option - update README - update tests --- README.md | 3 ++- src/AzureStorageServiceProvider.php | 7 ++++++- tests/AzureBlobStorageAdapterTest.php | 9 +++++++++ tests/TestCase.php | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 51e6815..9c13626 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ Then add this to the `disks` section of `config/filesystems.php`: 'key' => env('AZURE_STORAGE_KEY'), 'container' => env('AZURE_STORAGE_CONTAINER'), 'url' => env('AZURE_STORAGE_URL'), + 'prefix' => null, ], ``` -Finally, add the fields `AZURE_STORAGE_NAME`, `AZURE_STORAGE_KEY`, `AZURE_STORAGE_CONTAINER` and `AZURE_STORAGE_URL` to your `.env` file with the appropriate credentials. The `AZURE_STORAGE_URL` field is optional, this allows you to set a custom URL to be returned from `Storage::url()`, if using the `$root` continer the URL will be returned without the container path. Then you can set the `azure` driver as either your default or cloud driver and use it to fetch and retrieve files as usual. +Finally, add the fields `AZURE_STORAGE_NAME`, `AZURE_STORAGE_KEY`, `AZURE_STORAGE_CONTAINER` and `AZURE_STORAGE_URL` to your `.env` file with the appropriate credentials. The `AZURE_STORAGE_URL` field is optional, this allows you to set a custom URL to be returned from `Storage::url()`, if using the `$root` container the URL will be returned without the container path. A `prefix` can be optionally used. If it's not set, the container root is used. Then you can set the `azure` driver as either your default or cloud driver and use it to fetch and retrieve files as usual. # Support policy diff --git a/src/AzureStorageServiceProvider.php b/src/AzureStorageServiceProvider.php index 60ab35e..89a0025 100644 --- a/src/AzureStorageServiceProvider.php +++ b/src/AzureStorageServiceProvider.php @@ -26,7 +26,12 @@ public function boot() $config['key'] ); $client = BlobRestProxy::createBlobService($endpoint); - $adapter = new AzureBlobStorageAdapter($client, $config['container'], $config['url'] ?? null); + $adapter = new AzureBlobStorageAdapter( + $client, + $config['container'], + $config['url'] ?? null, + $config['prefix'] ?? null + ); return new Filesystem($adapter); }); } diff --git a/tests/AzureBlobStorageAdapterTest.php b/tests/AzureBlobStorageAdapterTest.php index d070b54..f832e03 100644 --- a/tests/AzureBlobStorageAdapterTest.php +++ b/tests/AzureBlobStorageAdapterTest.php @@ -58,4 +58,13 @@ public function it_handles_invalid_custom_url() $client = BlobRestProxy::createBlobService('DefaultEndpointsProtocol=https;AccountName=azure_account;AccountKey=' . base64_encode('azure_key')); $adapter = new AzureBlobStorageAdapter($client, 'azure_container', 'foo'); } + + /** @test */ + public function it_handles_custom_prefix() + { + $client = BlobRestProxy::createBlobService('DefaultEndpointsProtocol=https;AccountName=azure_account;AccountKey=' . base64_encode('azure_key')); + $adapter = new AzureBlobStorageAdapter($client, 'azure_container', null, 'test_path'); + + $this->assertEquals('https://azure_account.blob.core.windows.net/azure_container/test_path/test.txt', $adapter->getUrl('test_path/test.txt')); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index f68cd19..6eb6aad 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -27,6 +27,7 @@ protected function getEnvironmentSetUp($app) 'name' => 'MY_AZURE_STORAGE_NAME', 'key' => base64_encode('MY_AZURE_STORAGE_KEY'), 'container' => 'MY_AZURE_STORAGE_CONTAINER', + 'prefix' => null, ]); } }