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

Commit

Permalink
Resolve the Blob Client through the container
Browse files Browse the repository at this point in the history
Bind the `BlobRestProxy` to the container, so it can be resolved when the driver is created, but also when users need to access the client outside of the driver/adapter.

For example: `$client = app(BlobRestProxy::class)`
  • Loading branch information
sebdesign committed Oct 25, 2020
1 parent c450712 commit abafe1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/AzureStorageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ final class AzureStorageServiceProvider extends ServiceProvider
public function boot()
{
Storage::extend('azure', function ($app, $config) {
$endpoint = sprintf(
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;',
$config['name'],
$config['key']
);
if (isset($config['endpoint'])) {
$endpoint .= sprintf("BlobEndpoint=%s;", $config['endpoint']);
}
$client = BlobRestProxy::createBlobService($endpoint);
$client = $app->make(BlobRestProxy::class, $config);
$adapter = new AzureBlobStorageAdapter(
$client,
$config['container'],
Expand All @@ -47,6 +39,17 @@ public function boot()
*/
public function register()
{
//
$this->app->bind(BlobRestProxy::class, function ($app, $config) {
$config = empty($config) ? $app->make('config')->get('filesystems.disks.azure') : $config;
$endpoint = sprintf(
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;',
$config['name'],
$config['key']
);
if (isset($config['endpoint'])) {
$endpoint .= sprintf("BlobEndpoint=%s;", $config['endpoint']);
}
return BlobRestProxy::createBlobService($endpoint);
});
}
}
11 changes: 11 additions & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests;

use Illuminate\Support\Facades\Storage;
use MicrosoftAzure\Storage\Blob\BlobRestProxy;

final class ServiceProviderTest extends TestCase
{
Expand Down Expand Up @@ -46,4 +47,14 @@ public function custom_url_overrides_endpoint()

$this->assertEquals("$customUrl/$container/a.txt", Storage::url('a.txt'));
}

/** @test */
public function it_resolves_the_azure_client()
{
$this->assertTrue($this->app->bound(BlobRestProxy::class));

Storage::disk();

$this->assertTrue($this->app->resolved(BlobRestProxy::class));
}
}

0 comments on commit abafe1b

Please sign in to comment.