diff --git a/composer.json b/composer.json index faae9ac..b723de9 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "autoload": { "psr-4": { - "Ray\\PsrCacheModule\\": ["src/", "src-deprecated"] + "Ray\\PsrCacheModule\\": ["src/", "src-deprecated/"] } }, "autoload-dev": { diff --git a/src/MemcachdAdapter.php b/src-deprecated/MemcachdAdapter.php similarity index 93% rename from src/MemcachdAdapter.php rename to src-deprecated/MemcachdAdapter.php index b2160d0..5f1341b 100644 --- a/src/MemcachdAdapter.php +++ b/src-deprecated/MemcachdAdapter.php @@ -14,7 +14,7 @@ use function func_get_args; -/** @psalm-suppress PropertyNotSetInConstructor */ +/** @deprecated Use \Ray\PsrCacheModule\MemcachedAdapter instead */ class MemcachdAdapter extends OriginAdapter implements Serializable { use SerializableTrait; diff --git a/src/MemcachedAdapter.php b/src/MemcachedAdapter.php new file mode 100644 index 0000000..b360a00 --- /dev/null +++ b/src/MemcachedAdapter.php @@ -0,0 +1,36 @@ + $clientProvider + * + * @Named("memcached") + * @CacheNamespace("namespace") + */ + #[CacheNamespace('namespace')] + #[Named('memcached')] + public function __construct(ProviderInterface $clientProvider, string $namespace = '', int $defaultLifetime = 0, ?MarshallerInterface $marshaller = null) + { + $this->args = func_get_args(); + + parent::__construct($clientProvider->get(), $namespace, $defaultLifetime, $marshaller); + } +} diff --git a/tests/MemcachedAdapterTest.php b/tests/MemcachedAdapterTest.php index 5cdf9eb..301ead3 100644 --- a/tests/MemcachedAdapterTest.php +++ b/tests/MemcachedAdapterTest.php @@ -15,11 +15,11 @@ class MemcachedAdapterTest extends TestCase { - /** @return array{0:string, 1: MemcachdAdapter} */ + /** @return array{0:string, 1: MemcachedAdapter} */ public function testSerialize(): array { $provider = new MemcachedProvider([['127.0.0.1', '11211']]); - $adapter = new MemcachdAdapter($provider); + $adapter = new MemcachedAdapter($provider); $adapter->get('foo', static function (ItemInterface $item) { return 'foobar'; }); @@ -34,19 +34,19 @@ public function testSerialize(): array } /** - * @param array{0:string, 1: MemcachdAdapter} $adapters + * @param array{0:string, 1: MemcachedAdapter} $adapters * * @depends testSerialize */ public function testUnserialize(array $adapters): void { - $this->assertInstanceOf(MemcachdAdapter::class, $adapters[1]); + $this->assertInstanceOf(MemcachedAdapter::class, $adapters[1]); $this->assertSame('foobar', $adapters[1]->get('foo', static function (ItemInterface $item) { return '_no_serve_in_object'; })); $adapter0 = unserialize($adapters[0]); - $this->assertInstanceOf(MemcachdAdapter::class, $adapter0); + $this->assertInstanceOf(MemcachedAdapter::class, $adapter0); $this->assertSame('foobar', $adapter0->get('foo', static function (ItemInterface $item) { return '_no_serve_in_serialize'; })); @@ -59,11 +59,11 @@ protected function configure(): void { $this->install(new CacheNamespaceModule('a')); $this->install(new CacheDirModule('/tmp/a')); - $this->bind(AbstractAdapter::class)->to(MemcachdAdapter::class); + $this->bind(AbstractAdapter::class)->to(MemcachedAdapter::class); $this->install(new Psr6MemcachedModule('127.0.0.1:6379:1')); } }); $adapter = $injector->getInstance(AbstractAdapter::class); - $this->assertInstanceOf(MemcachdAdapter::class, $adapter); + $this->assertInstanceOf(MemcachedAdapter::class, $adapter); } }