From d8eefdfc6fd2d9e4f5bfa63d9ab545bfa0605fdd Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Sat, 9 Mar 2024 18:03:41 +0100 Subject: [PATCH] Added ability to (dangerously) mount additional filesystems. --- src/MountManager.php | 23 ++++++++++++++--------- src/MountManagerTest.php | 12 ++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/MountManager.php b/src/MountManager.php index 66d5f052a..2ef2288ea 100644 --- a/src/MountManager.php +++ b/src/MountManager.php @@ -33,6 +33,15 @@ public function __construct(array $filesystems = [], array $config = []) $this->config = new Config($config); } + /** + * It is not recommended to mount filesystems after creation because interacting + * with the Mount Manager becomes unpredictable. Use this as an escape hatch. + */ + public function dangerouslyMountFilesystems(string $key, FilesystemOperator $filesystem): void + { + $this->mountFilesystem($key, $filesystem); + } + /** * @param array $filesystems */ @@ -156,15 +165,15 @@ public function mimeType(string $location): string } } - public function visibility(string $location): string + public function visibility(string $path): string { /** @var FilesystemOperator $filesystem */ - [$filesystem, $path] = $this->determineFilesystemAndPath($location); + [$filesystem, $location] = $this->determineFilesystemAndPath($path); try { - return $filesystem->visibility($path); + return $filesystem->visibility($location); } catch (UnableToRetrieveMetadata $exception) { - throw UnableToRetrieveMetadata::visibility($location, $exception->reason(), $exception); + throw UnableToRetrieveMetadata::visibility($path, $exception->reason(), $exception); } } @@ -318,11 +327,7 @@ private function mountFilesystems(array $filesystems): void } } - /** - * @param mixed $key - * @param mixed $filesystem - */ - private function guardAgainstInvalidMount($key, $filesystem): void + private function guardAgainstInvalidMount(mixed $key, mixed $filesystem): void { if ( ! is_string($key)) { throw UnableToMountFilesystem::becauseTheKeyIsNotValid($key); diff --git a/src/MountManagerTest.php b/src/MountManagerTest.php index 301b192fd..6dbd51efd 100644 --- a/src/MountManagerTest.php +++ b/src/MountManagerTest.php @@ -554,6 +554,18 @@ public function listing_contents(): void $this->assertCount(3, $contents); } + /** + * @test + */ + public function dangerously_mounting_additional_filesystems(): void + { + $this->firstFilesystem->write('contents.txt', 'file contents'); + + $this->mountManager->dangerouslyMountFilesystems('unknown', $this->firstFilesystem); + + $this->assertTrue($this->mountManager->fileExists('unknown://contents.txt')); + } + /** * @test */