-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] CacheItem must be compatible #978
Comments
@c-o-m-m-a-n-d-e-r thanks for mentioning this issue as well as the community message with my comments about the issue; @serbanghita currently for a number of my clients that are using @humhub as of v1.17.0-beta.4 which introduces this package can not be updated correctly due to the Cache class not being compatible with the interface, and I've had to use the following complete code and manually do this with a number of instances already; Complete CodeReplace https://github.com/serbanghita/Mobile-Detect/blob/4.8.x/src/Cache/Cache.php to be compatible with <?php
namespace Detection\Cache;
use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\InvalidArgumentException;
class Cache implements CacheInterface
{
protected array $cache_db = [];
public function count(): int
{
return count($this->cache_db);
}
/**
* @return array{string}
*/
public function getKeys(): array
{
return array_keys($this->cache_db);
}
public function get($key, $default = null)
{
if (!is_string($key) || $key === '') {
throw new InvalidArgumentException('Invalid cache key');
}
return $this->cache_db[$key] ?? $default;
}
public function set($key, $value, $ttl = null): bool
{
if (!is_string($key) || $key === '') {
throw new InvalidArgumentException('Invalid cache key');
}
$this->cache_db[$key] = ['value' => $value, 'ttl' => $ttl];
return true;
}
public function delete($key): bool
{
unset($this->cache_db[$key]);
return true;
}
public function clear(): bool
{
$this->cache_db = [];
return true;
}
public function getMultiple($keys, $default = null): iterable
{
$results = [];
foreach ($keys as $key) {
$results[$key] = $this->get($key, $default);
}
return $results;
}
public function setMultiple($values, $ttl = null): bool
{
foreach ($values as $key => $value) {
$this->set($key, $value, $ttl);
}
return true;
}
public function deleteMultiple($keys): bool
{
foreach ($keys as $key) {
$this->delete($key);
}
return true;
}
public function has($key): bool
{
return isset($this->cache_db[$key]);
}
} |
@c-o-m-m-a-n-d-e-r how do you install and update HumHub? From the zip? https://docs.humhub.org/docs/admin/installation#download-and-extract It seems that you install it from git if you use composer.
What cache are you using? Have you got specific configuration in your common.php file, such as some similar to: 'cache' => [
'class' => \yii\caching\DummyCache::class,
], Thank you for your help. |
@marc-farre sorry i don't use HumHub ... i had the same error in another project so i do some research and found the solution from @ArchBlood |
@c-o-m-m-a-n-d-e-r Sorry, by receiving a notification about this topic, I thought I was writing in the HumHub Git repository... However, if both of you could send me the result of |
From my end I see no issues;
|
@ArchBlood Thanks. I compared with a diff tool, and I have the same list (some versions could be updated, but I doubt it will fix this issue). |
@marc-farre here is my final judgement about this issue, the Cache class doesn't fully comply with PSR-16 due to the following; 1. Return Type of
|
#978 (comment) will fix the issue, but it can always be improved for backwards compatibility which is what I think was the intent of the current implementation? |
Hi,
i'm getting the same Error like here:
https://community.humhub.com/comment/perma?id=51033
The Error is :
Declaration of Detection\Cache\Cache::get(string $key, mixed $default = null): ?Detection\Cache\CacheItem must be compatible with PsrExt\SimpleCache\CacheInterface::get($key, $default = <default>)
Already tried reinstalling via composer without luck.
Usage is only:
use Detection\MobileDetect; $detect = new MobileDetect(); $isMobile = $detect->isMobile();
The text was updated successfully, but these errors were encountered: