From b11aeb8c92dfdd5911264c6bdef366dbb1056727 Mon Sep 17 00:00:00 2001 From: "brecht.vermeersch" Date: Sun, 10 Nov 2024 18:07:54 +0100 Subject: [PATCH 1/3] add public url generation --- composer.json | 4 ++-- src/AzureStorageBlobAdapter.php | 5 +++++ src/AzureStorageBlobServiceProvider.php | 2 +- tests/AzureStorageBlobAdapterTest.php | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 6748039..961b7e5 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "autoload-dev": { "psr-4": { - "AzureOss\\LaravelAzureStorageBlob\\Tests": "tests/" + "AzureOss\\LaravelAzureStorageBlob\\Tests\\": "tests/" } }, "authors": [ @@ -23,7 +23,7 @@ "php": "^8.1", "illuminate/filesystem": "^10|^11", "illuminate/support": "^10|^11", - "azure-oss/storage-blob-flysystem": "^1.1" + "azure-oss/storage-blob-flysystem": "^1.2" }, "require-dev": { "laravel/pint": "^1.17", diff --git a/src/AzureStorageBlobAdapter.php b/src/AzureStorageBlobAdapter.php index 54fc14d..40f7d0f 100644 --- a/src/AzureStorageBlobAdapter.php +++ b/src/AzureStorageBlobAdapter.php @@ -31,6 +31,11 @@ public function __construct(array $config) ); } + public function url($path) + { + return $this->adapter->publicUrl($path, new Config); + } + /** @phpstan-ignore-next-line */ public function temporaryUrl($path, $expiration, array $options = []) { diff --git a/src/AzureStorageBlobServiceProvider.php b/src/AzureStorageBlobServiceProvider.php index b44fcb1..25d4d01 100644 --- a/src/AzureStorageBlobServiceProvider.php +++ b/src/AzureStorageBlobServiceProvider.php @@ -26,7 +26,7 @@ public function boot(): void if (isset($config['prefix']) && ! is_string($config['prefix'])) { throw new \InvalidArgumentException('The [prefix] must be a string in the disk configuration.'); } - + if (isset($config['root']) && ! is_string($config['root'])) { throw new \InvalidArgumentException('The [root] must be a string in the disk configuration.'); } diff --git a/tests/AzureStorageBlobAdapterTest.php b/tests/AzureStorageBlobAdapterTest.php index 230a889..df1359c 100644 --- a/tests/AzureStorageBlobAdapterTest.php +++ b/tests/AzureStorageBlobAdapterTest.php @@ -53,6 +53,10 @@ public function driver_works(): void 'content', Http::get($driver->temporaryUrl('file.txt', now()->addMinute()))->body() ); + self::assertEquals( + 'content', + Http::get($driver->url('file.txt'))->body() + ); $driver->copy('file.txt', 'file2.txt'); From 561e4da43745f8e8d1af013df38e282170cc550c Mon Sep 17 00:00:00 2001 From: "brecht.vermeersch" Date: Sun, 10 Nov 2024 18:11:05 +0100 Subject: [PATCH 2/3] allow php8.1 in tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 961b7e5..1171b9f 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ }, "require-dev": { "laravel/pint": "^1.17", - "orchestra/testbench": "^9.2", + "orchestra/testbench": "^8.1|^9.2", "phpstan/phpstan": "^1.11", "phpstan/phpstan-deprecation-rules": "^1.2", "phpstan/phpstan-strict-rules": "^1.6" From 50348c240a2bc9b8224edc1d892eccaa017c0c94 Mon Sep 17 00:00:00 2001 From: "brecht.vermeersch" Date: Sun, 10 Nov 2024 18:14:56 +0100 Subject: [PATCH 3/3] fix tests --- tests/AzureStorageBlobAdapterTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/AzureStorageBlobAdapterTest.php b/tests/AzureStorageBlobAdapterTest.php index df1359c..bb4c02a 100644 --- a/tests/AzureStorageBlobAdapterTest.php +++ b/tests/AzureStorageBlobAdapterTest.php @@ -4,6 +4,7 @@ use AzureOss\LaravelAzureStorageBlob\AzureStorageBlobAdapter; use AzureOss\LaravelAzureStorageBlob\AzureStorageBlobServiceProvider; +use AzureOss\Storage\Blob\BlobServiceClient; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Storage; use Orchestra\Testbench\TestCase; @@ -34,6 +35,10 @@ public function it_resolves_from_manager(): void #[Test] public function driver_works(): void { + BlobServiceClient::fromConnectionString(env('AZURE_STORAGE_CONNECTION_STRING')) + ->getContainerClient(env('AZURE_STORAGE_CONTAINER')) + ->createIfNotExists(); + $driver = Storage::disk('azure'); // cleanup from previous test runs