Skip to content

Commit

Permalink
Enable public urls for Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Oct 5, 2022
1 parent e5968d9 commit d2d5fa6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/AzureBlobStorage/AzureBlobStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@

use function stream_get_contents;

class AzureBlobStorageAdapter implements FilesystemAdapter
class AzureBlobStorageAdapter implements FilesystemAdapter, PublicUrlGenerator
{
/** @var string[] */
private const META_OPTIONS = [
Expand Down Expand Up @@ -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);
}
}
17 changes: 17 additions & 0 deletions src/AzureBlobStorage/AzureBlobStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit d2d5fa6

Please sign in to comment.