Skip to content

Commit

Permalink
Turned static adapter into a static registry.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Sep 6, 2022
1 parent 8e58e6f commit 12f635f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 126 deletions.
19 changes: 19 additions & 0 deletions src/InMemory/StaticInMemoryAdapterRegistry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace League\Flysystem\InMemory;

class StaticInMemoryAdapterRegistry
{
/** @var array<string, InMemoryFilesystemAdapter> */
private static array $filesystems = [];

public static function get(string $name = 'default'): InMemoryFilesystemAdapter
{
return static::$filesystems[$name] ??= new InMemoryFilesystemAdapter();
}

public static function deleteAllFilesystems(): void
{
self::$filesystems = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
use League\Flysystem\Config;
use League\Flysystem\FilesystemAdapter;

class StaticInMemoryFilesystemAdapterTest extends InMemoryFilesystemAdapterTest
class StaticInMemoryAdapterRegistryTest extends InMemoryFilesystemAdapterTest
{
/**
* @test
*/
public function using_different_name_to_segment_adapters(): void
{
$first = new StaticInMemoryFilesystemAdapter();
$second = new StaticInMemoryFilesystemAdapter('second');
$first = StaticInMemoryAdapterRegistry::get();
$second = StaticInMemoryAdapterRegistry::get('second');

$first->write('foo.txt', 'foo', new Config());
$second->write('bar.txt', 'bar', new Config());
Expand All @@ -29,29 +29,29 @@ public function using_different_name_to_segment_adapters(): void
*/
public function files_persist_between_instances(): void
{
$first = new StaticInMemoryFilesystemAdapter();
$second = new StaticInMemoryFilesystemAdapter('second');
$first = StaticInMemoryAdapterRegistry::get();
$second = StaticInMemoryAdapterRegistry::get('second');

$first->write('foo.txt', 'foo', new Config());
$second->write('bar.txt', 'bar', new Config());

$this->assertTrue($first->fileExists('foo.txt'));
$this->assertTrue($second->fileExists('bar.txt'));

$first = new StaticInMemoryFilesystemAdapter();
$second = new StaticInMemoryFilesystemAdapter('second');
$first = StaticInMemoryAdapterRegistry::get();
$second = StaticInMemoryAdapterRegistry::get('second');

$this->assertTrue($first->fileExists('foo.txt'));
$this->assertTrue($second->fileExists('bar.txt'));
}

protected function tearDown(): void
{
StaticInMemoryFilesystemAdapter::deleteAllFilesystems();
StaticInMemoryAdapterRegistry::deleteAllFilesystems();
}

protected static function createFilesystemAdapter(): FilesystemAdapter
{
return new StaticInMemoryFilesystemAdapter();
return StaticInMemoryAdapterRegistry::get();
}
}
117 changes: 0 additions & 117 deletions src/InMemory/StaticInMemoryFilesystemAdapter.php

This file was deleted.

0 comments on commit 12f635f

Please sign in to comment.