Skip to content

Commit 92f05c0

Browse files
author
brecht.vermeersch
committed
add visibility handling
1 parent 6c6b008 commit 92f05c0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/AzureBlobStorageAdapter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@
3333

3434
class AzureBlobStorageAdapter implements FilesystemAdapter, ChecksumProvider, TemporaryUrlGenerator
3535
{
36+
public const ON_VISIBILITY_THROW_ERROR = 'throw';
37+
public const ON_VISIBILITY_IGNORE = 'ignore';
38+
3639
private readonly MimeTypeDetector $mimeTypeDetector;
3740
private readonly PathPrefixer $prefixer;
3841

3942
public function __construct(
4043
private readonly BlobContainerClient $containerClient,
4144
string $prefix = "",
4245
?MimeTypeDetector $mimeTypeDetector = null,
46+
private readonly string $visibilityHandling = self::ON_VISIBILITY_THROW_ERROR,
4347
) {
4448
$this->prefixer = new PathPrefixer($prefix);
4549
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
@@ -165,7 +169,9 @@ public function createDirectory(string $path, Config $config): void
165169

166170
public function setVisibility(string $path, string $visibility): void
167171
{
168-
throw UnableToSetVisibility::atLocation($path, "Azure does not support this operation.");
172+
if ($this->visibilityHandling === self::ON_VISIBILITY_THROW_ERROR) {
173+
throw UnableToSetVisibility::atLocation($path, 'Azure does not support this operation.');
174+
}
169175
}
170176

171177
public function visibility(string $path): FileAttributes

tests/AzureBlobStorageTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase;
1111
use League\Flysystem\Config;
1212
use League\Flysystem\FilesystemAdapter;
13+
use League\Flysystem\UnableToSetVisibility;
1314
use League\Flysystem\Visibility;
15+
use PHPUnit\Framework\Attributes\Test;
1416

1517
class AzureBlobStorageTest extends FilesystemAdapterTestCase
1618
{
@@ -163,4 +165,29 @@ public function file_exists_on_directory_is_false(): void
163165
$this->assertFalse($adapter->fileExists('test'));
164166
});
165167
}
168+
169+
#[Test]
170+
public function setting_visibility_can_be_ignored_not_supported(): void
171+
{
172+
$this->givenWeHaveAnExistingFile('some-file.md');
173+
$this->expectNotToPerformAssertions();
174+
175+
$adapter = new AzureBlobStorageAdapter(
176+
self::createContainerClient(),
177+
visibilityHandling: AzureBlobStorageAdapter::ON_VISIBILITY_IGNORE,
178+
);
179+
180+
$adapter->setVisibility('some-file.md', 'public');
181+
}
182+
183+
#[Test]
184+
public function setting_visibility_causes_errors(): void
185+
{
186+
$this->givenWeHaveAnExistingFile('some-file.md');
187+
$adapter = $this->adapter();
188+
189+
$this->expectException(UnableToSetVisibility::class);
190+
191+
$adapter->setVisibility('some-file.md', 'public');
192+
}
166193
}

0 commit comments

Comments
 (0)