Skip to content

Commit f6a0cbf

Browse files
author
brecht.vermeersch
committed
add temporary url support
1 parent 715c579 commit f6a0cbf

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/AzureStorageBlobAdapter.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace AzureOss\LaravelAzureStorageBlob;
4+
5+
use AzureOss\FlysystemAzureBlobStorage\AzureBlobStorageAdapter;
6+
use AzureOss\Storage\Blob\BlobServiceClient;
7+
use Illuminate\Filesystem\FilesystemAdapter;
8+
use League\Flysystem\Config;
9+
use League\Flysystem\Filesystem;
10+
11+
/**
12+
* @internal
13+
*/
14+
final class AzureStorageBlobAdapter extends FilesystemAdapter
15+
{
16+
public function __construct(array $config)
17+
{
18+
$serviceClient = BlobServiceClient::fromConnectionString($config['connection_string']);
19+
$containerClient = $serviceClient->getContainerClient($config['container']);
20+
$adapter = new AzureBlobStorageAdapter($containerClient, $config['prefix'] ?? "");
21+
22+
parent::__construct(
23+
new Filesystem($adapter, $config),
24+
$adapter,
25+
$config
26+
);
27+
}
28+
29+
public function temporaryUrl($path, $expiration, array $options = [])
30+
{
31+
$options["permissions"] = $options["permissions"] ?? "r";
32+
33+
return $this->adapter->temporaryUrl($path, $expiration, new Config($options));
34+
}
35+
36+
public function temporaryUploadUrl($path, $expiration, array $options = [])
37+
{
38+
$options["permissions"] = $options["permissions"] ?? "w";
39+
40+
return $this->adapter->temporaryUrl($path, $expiration, new Config($options));
41+
}
42+
}

src/AzureStorageBlobServiceProvider.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
namespace AzureOss\LaravelAzureStorageBlob;
44

5-
use AzureOss\FlysystemAzureBlobStorage\AzureBlobStorageAdapter;
6-
use AzureOss\Storage\Blob\BlobServiceClient;
75
use Illuminate\Contracts\Foundation\Application;
86
use Illuminate\Filesystem\FilesystemAdapter;
97
use Illuminate\Support\Facades\Storage;
108
use Illuminate\Support\ServiceProvider;
11-
use League\Flysystem\Filesystem;
129

1310
/**
1411
* @internal
@@ -18,15 +15,7 @@ final class AzureStorageBlobServiceProvider extends ServiceProvider
1815
public function boot(): void
1916
{
2017
Storage::extend('azure-storage-blob', function (Application $app, array $config): FilesystemAdapter {
21-
$serviceClient = BlobServiceClient::fromConnectionString($config['connection_string']);
22-
$containerClient = $serviceClient->getContainerClient($config['container']);
23-
$adapter = new AzureBlobStorageAdapter($containerClient, $config['prefix'] ?? "");
24-
25-
return new FilesystemAdapter(
26-
new Filesystem($adapter, $config),
27-
$adapter,
28-
$config
29-
);
18+
return new AzureStorageBlobAdapter($config);
3019
});
3120
}
3221
}

0 commit comments

Comments
 (0)