Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Cache] ChainAdapter accepts CacheItemPoolInterface, so it should work with adapter of CacheItemPoolInterface other than \Symfony\Component\Cache\Adapter\AdapterInterface #60160

Closed
@PatchRanger

Description

@PatchRanger

Symfony version(s) affected

7.*

Description

ChainAdapter accepts list ofCacheItemPoolInterface.
It makes me assuming that I can use it together with eitherAdapterInterface or any external class implementingCacheItemPoolInterface.
If I got it correct, I can do such thing in my DI asCacheItemPoolInterface:

newChainAdapter(  adapters: [new \Symfony\Component\Cache\Adapter\ArrayAdapter(storeSerialized:false),    YiiHelper::get(\Yii2Extended\Yii2Cache\Psr6ToYii2Cache::class),// it implements CacheItemPoolInterface  ],);

But I can't. It leads to the TypeError (see below in Additonal context).

How to reproduce

I've created a minimal script to reproduce. it's attached.
reproducer.php.txt

Here's the text of the script, if that's more convenient.

<?phprequire_once__DIR__ .'/vendor/autoload.php';useSymfony\Component\Cache\Adapter\ChainAdapter;useYii2Extended\Yii2Cache\Psr6ToYii2Cache;$chainAdapter =newChainAdapter(    adapters: [new \Symfony\Component\Cache\Adapter\ArrayAdapter(storeSerialized:false),newPsr6ToYii2Cache(new \yii\caching\ArrayCache()),    ],);$cacheKey ='foo';$item =$chainAdapter->getItem($cacheKey);if ($item->isHit()) {echo'isHit',"\n";echo$item->get(),"\n";}$item->set('bar');echo'before save',"\n";$chainAdapter->save($item);echo'after save',"\n";

In place of thePsr6ToYii2Cache can be any external (i.e., not implementing the\Symfony\Component\Cache\Adapter\AdapterInterface) class that implements theCacheItemPoolInterface.

Possible Solution

I've fixed it locally by such fix:
vendor/symfony/cache/CacheItem.php

- protected ?ItemInterface$innerItem =null;+ protected ?\Psr\Cache\CacheItemInterface$innerItem = null;

In my view it's adequate: as long asChainAdapter acceptsCacheItemPoolInterface, it's normal thatinnerItem should be ofCacheItemInterface.

Additional Context

reproducer.php without fix leads to such error message:

PHP Fatal error: Uncaught TypeError: Cannot assign Yii2Extended\Yii2Cache\Psr6ToYii2CacheItem to property Symfony\Component\Cache\CacheItem::$innerItem of type ?Symfony\Contracts\Cache\ItemInterface in /code/vendor/symfony/cache/Adapter/ProxyAdapter.php:60

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp