Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from hakan0xFF/master
Browse files Browse the repository at this point in the history
feat: support custom prefix option
  • Loading branch information
matthewbdaly authored Jul 22, 2019
2 parents 81de7ba + 9a6259e commit f570d87
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion src/AzureStorageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
9 changes: 9 additions & 0 deletions tests/AzureBlobStorageAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}

0 comments on commit f570d87

Please sign in to comment.