Skip to content

Commit

Permalink
Added ability to (dangerously) mount additional filesystems.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Mar 9, 2024
1 parent 85f70d1 commit d8eefdf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/MountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,FilesystemOperator> $filesystems
*/
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/MountManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit d8eefdf

Please sign in to comment.