Skip to content

Commit 031f57e

Browse files
authored
Merge pull request #3 from Moln/develop
Update deps
2 parents ebcfce3 + e94ee94 commit 031f57e

File tree

2 files changed

+63
-29
lines changed

2 files changed

+63
-29
lines changed

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
"ext-sockets": "*",
1919
"doctrine/collections": "^1.3",
2020
"doctrine/dbal": "^3.0",
21-
"psr/simple-cache": "^1.0",
22-
"symfony/dependency-injection": "^3.1|^4.0|^5.0",
23-
"symfony/event-dispatcher": "^3.1|^4.0|^5.0"
21+
"psr/simple-cache": "^1.0 | ^3.0",
22+
"symfony/event-dispatcher": "^3.1|^4.0|^5.0|^6.0"
2423
},
2524
"require-dev": {
2625
"phpunit/phpunit": "^9.0"

src/MySQLReplication/Cache/ArrayCache.php

+61-26
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,68 @@
33

44
namespace MySQLReplication\Cache;
55

6-
use MySQLReplication\Config\Config;
6+
use Composer\InstalledVersions;
77
use Psr\SimpleCache\CacheInterface;
88

9-
class ArrayCache implements CacheInterface
10-
{
9+
if (class_exists(InstalledVersions::class) && version_compare(InstalledVersions::getVersion("psr/simple-cache"), '3.0.0', ">=")) {
10+
class ArrayCache implements CacheInterface
11+
{
12+
use ArrayCacheTrait;
13+
14+
/**
15+
* @inheritDoc
16+
*/
17+
public function get(string $key, $default = null): mixed
18+
{
19+
return $this->has($key) ? $this->tableMapCache[$key] : $default;
20+
}
21+
22+
/**
23+
* @inheritDoc
24+
*/
25+
public function getMultiple(iterable $keys, $default = null): iterable
26+
{
27+
$data = [];
28+
foreach ($keys as $key) {
29+
if ($this->has($key)) {
30+
$data[$key] = $this->tableMapCache[$key];
31+
}
32+
}
33+
34+
return [] !== $data ? $data : $default;
35+
}
36+
}
37+
} else {
38+
class ArrayCache implements CacheInterface
39+
{
40+
use ArrayCacheTrait;
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
public function get($key, $default = null)
46+
{
47+
return $this->has($key) ? $this->tableMapCache[$key] : $default;
48+
}
49+
50+
/**
51+
* @inheritDoc
52+
*/
53+
public function getMultiple($keys, $default = null)
54+
{
55+
$data = [];
56+
foreach ($keys as $key) {
57+
if ($this->has($key)) {
58+
$data[$key] = $this->tableMapCache[$key];
59+
}
60+
}
61+
62+
return [] !== $data ? $data : $default;
63+
}
64+
}
65+
}
66+
67+
trait ArrayCacheTrait {
1168
private $tableMapCache = [];
1269

1370
/**
@@ -20,13 +77,6 @@ public function __construct(int $tableCacheSize = 128)
2077
$this->tableCacheSize = $tableCacheSize;
2178
}
2279

23-
/**
24-
* @inheritDoc
25-
*/
26-
public function get($key, $default = null)
27-
{
28-
return $this->has($key) ? $this->tableMapCache[$key] : $default;
29-
}
3080

3181
/**
3282
* @inheritDoc
@@ -46,21 +96,6 @@ public function clear(): bool
4696
return true;
4797
}
4898

49-
/**
50-
* @inheritDoc
51-
*/
52-
public function getMultiple($keys, $default = null)
53-
{
54-
$data = [];
55-
foreach ($keys as $key) {
56-
if ($this->has($key)) {
57-
$data[$key] = $this->tableMapCache[$key];
58-
}
59-
}
60-
61-
return [] !== $data ? $data : $default;
62-
}
63-
6499
/**
65100
* @inheritDoc
66101
*/
@@ -114,4 +149,4 @@ public function delete($key): bool
114149

115150
return true;
116151
}
117-
}
152+
}

0 commit comments

Comments
 (0)