diff --git a/src/AzureBlobStorage/AzureBlobStorageAdapter.php b/src/AzureBlobStorage/AzureBlobStorageAdapter.php index 69efc3ca4..cab558ce5 100644 --- a/src/AzureBlobStorage/AzureBlobStorageAdapter.php +++ b/src/AzureBlobStorage/AzureBlobStorageAdapter.php @@ -19,6 +19,7 @@ use League\Flysystem\UnableToRetrieveMetadata; use League\Flysystem\UnableToSetVisibility; use League\Flysystem\UnableToWriteFile; +use League\Flysystem\UrlGeneration\PublicUrlGenerator; use League\MimeTypeDetection\FinfoMimeTypeDetector; use League\MimeTypeDetection\MimeTypeDetector; use MicrosoftAzure\Storage\Blob\BlobRestProxy; @@ -31,7 +32,7 @@ use function stream_get_contents; -class AzureBlobStorageAdapter implements FilesystemAdapter +class AzureBlobStorageAdapter implements FilesystemAdapter, PublicUrlGenerator { /** @var string[] */ private const META_OPTIONS = [ @@ -335,4 +336,11 @@ private function normalizeBlobProperties(string $path, BlobProperties $propertie $properties->getContentType() ); } + + public function publicUrl(string $path, Config $config): string + { + $location = $this->prefixer->prefixPath($path); + + return $this->client->getBlobUrl($this->container, $location); + } } diff --git a/src/AzureBlobStorage/AzureBlobStorageTest.php b/src/AzureBlobStorage/AzureBlobStorageTest.php index 1d144c8c6..745849bb4 100644 --- a/src/AzureBlobStorage/AzureBlobStorageTest.php +++ b/src/AzureBlobStorage/AzureBlobStorageTest.php @@ -10,6 +10,8 @@ use League\Flysystem\UnableToSetVisibility; use League\Flysystem\Visibility; use MicrosoftAzure\Storage\Blob\BlobRestProxy; + +use function file_get_contents; use function getenv; /** @@ -201,4 +203,19 @@ public function creating_a_directory(): void { $this->markTestSkipped('This adapter does not support creating directories'); } + + /** + * @test + */ + public function generating_a_public_url(): void + { + /** @var AzureBlobStorageAdapter $adapter */ + $adapter = $this->adapter(); + $adapter->write('some/path.txt', 'public contents', new Config(['visibility' => 'public'])); + + $url = $adapter->publicUrl('some/path.txt', new Config()); + $contents = file_get_contents($url); + + self::assertEquals('public contents', $contents); + } }