Skip to content

Commit

Permalink
Merge pull request #13 from Crell/registry-has
Browse files Browse the repository at this point in the history
Add has() method to the registry to make it easier to avoid double-registering
  • Loading branch information
elazar committed Aug 15, 2024
2 parents a0bed9c + 8fe0be6 commit 13bf51e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FilesystemRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function get(
return $this->filesystems[$protocol];
}

public function has(string $protocol): bool
{
return array_key_exists($protocol, $this->filesystems);
}

private function checkForProtocol(string $protocol): void
{
if (!isset($this->filesystems[$protocol])) {
Expand Down
8 changes: 8 additions & 0 deletions tests/FilesystemRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@
FlystreamException::class,
'Specified protocol is not registered: foo'
);

it('knows when a protocol is already registered', function () {
expect($this->registry->has('beep'))->toEqual(false);
$this->registry->register('beep', $this->filesystem);
expect($this->registry->has('beep'))->toEqual(true);
$this->registry->unregister('beep');
expect($this->registry->has('beep'))->toEqual(false);
});

0 comments on commit 13bf51e

Please sign in to comment.