Skip to content

Commit e53f82c

Browse files
authored
Merge pull request #110 from Slamdunk/support-persistence-3
Add support for `doctrine/cache:v2`
2 parents 2905a5f + 9db19b7 commit e53f82c

13 files changed

+309
-323
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ jobs:
1313
- 'latest'
1414
- 'lowest'
1515

16-
name: PHP ${{ matrix.php-version }}
17-
1816
steps:
1917
- name: Checkout
2018
uses: actions/checkout@v4

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"homepage": "https://github.com/Roave/psr-container-doctrine",
1818
"require": {
1919
"php": "~8.1.0 || ~8.2.0",
20-
"doctrine/annotations": "^1.14.2 || ^2.0",
21-
"doctrine/cache": "^1.13.0",
20+
"doctrine/annotations": "^1.14.3 || ^2.0.1",
21+
"doctrine/cache": "^2.2",
2222
"doctrine/common": "^3.4.3",
2323
"doctrine/dbal": "^3.7.1",
2424
"doctrine/event-manager": "^1.2.0 || ^2.0",
2525
"doctrine/migrations": "^3.6.0",
2626
"doctrine/orm": "^2.16.2",
27-
"doctrine/persistence": "^2.5.6 || ^3.1",
28-
"psr/cache": "^1.0.1 || ^2.0.0 || ^3.0.0",
29-
"psr/container": "^1.0 || ^2.0"
27+
"doctrine/persistence": "^2.5.7 || ^3.2",
28+
"psr/cache": "^2.0.0 || ^3.0.0",
29+
"psr/container": "^1.1.2 || ^2.0.2"
3030
},
3131
"require-dev": {
3232
"doctrine/coding-standard": "^12.0.0",

composer.lock

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"require": {
44
"php": "~8.1.0 || ~8.2.0",
55
"illuminate/container": "^10.29",
6-
"laminas/laminas-servicemanager": "^3.22.1"
6+
"laminas/laminas-servicemanager": "^3.22.1",
7+
"symfony/cache": "^6.3"
78
},
89
"config": {
910
"platform": {

example/full-config.php

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use Doctrine\Common\Cache\ApcuCache;
6-
use Doctrine\Common\Cache\ArrayCache;
7-
use Doctrine\Common\Cache\ChainCache;
8-
use Doctrine\Common\Cache\FilesystemCache;
9-
use Doctrine\Common\Cache\MemcacheCache;
10-
use Doctrine\Common\Cache\MemcachedCache;
11-
use Doctrine\Common\Cache\PhpFileCache;
12-
use Doctrine\Common\Cache\PredisCache;
13-
use Doctrine\Common\Cache\RedisCache;
14-
use Doctrine\Common\Cache\WinCacheCache;
15-
use Doctrine\Common\Cache\XcacheCache;
16-
use Doctrine\Common\Cache\ZendDataCache;
175
use Doctrine\DBAL\Driver as DbalDriver;
186
use Doctrine\DBAL\Driver\Middleware;
197
use Doctrine\DBAL\Driver\SQLite3\Driver;
@@ -29,13 +17,15 @@
2917
use Roave\PsrContainerDoctrine\Migrations\CommandFactory;
3018
use Roave\PsrContainerDoctrine\Migrations\ConfigurationLoaderFactory;
3119
use Roave\PsrContainerDoctrine\Migrations\DependencyFactoryFactory;
20+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
21+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
3222

3323
return [
3424
'doctrine' => [
3525
'configuration' => [
3626
'orm_default' => [
3727
'result_cache' => 'array',
38-
'metadata_cache' => 'array',
28+
'metadata_cache' => 'filesystem',
3929
'query_cache' => 'array',
4030
'hydration_cache' => 'array',
4131
'driver' => 'orm_default', // Actually defaults to the configuration config key, not hard-coded
@@ -104,64 +94,15 @@
10494
],
10595
],
10696
'cache' => [
107-
'apcu' => [
108-
'class' => ApcuCache::class,
109-
'namespace' => 'psr-container-doctrine',
110-
],
11197
'array' => [
112-
'class' => ArrayCache::class,
113-
'namespace' => 'psr-container-doctrine',
98+
'class' => ArrayAdapter::class,
11499
],
115100
'filesystem' => [
116-
'class' => FilesystemCache::class,
117-
'directory' => 'data/cache/DoctrineCache',
118-
'namespace' => 'psr-container-doctrine',
119-
],
120-
'memcache' => [
121-
'class' => MemcacheCache::class,
122-
'instance' => 'my_memcache_alias',
123-
'namespace' => 'psr-container-doctrine',
124-
],
125-
'memcached' => [
126-
'class' => MemcachedCache::class,
127-
'instance' => 'my_memcached_alias',
128-
'namespace' => 'psr-container-doctrine',
129-
],
130-
'phpfile' => [
131-
'class' => PhpFileCache::class,
132-
'directory' => 'data/cache/DoctrineCache',
133-
'namespace' => 'psr-container-doctrine',
134-
],
135-
'predis' => [
136-
'class' => PredisCache::class,
137-
'instance' => 'my_predis_alias',
138-
'namespace' => 'psr-container-doctrine',
139-
],
140-
'redis' => [
141-
'class' => RedisCache::class,
142-
'instance' => 'my_redis_alias',
143-
'namespace' => 'psr-container-doctrine',
144-
],
145-
'wincache' => [
146-
'class' => WinCacheCache::class,
147-
'namespace' => 'psr-container-doctrine',
148-
],
149-
'xcache' => [
150-
'class' => XcacheCache::class,
151-
'namespace' => 'psr-container-doctrine',
152-
],
153-
'zenddata' => [
154-
'class' => ZendDataCache::class,
155-
'namespace' => 'psr-container-doctrine',
101+
'class' => FilesystemAdapter::class,
156102
],
157103
// 'my_cache_provider' => [
158104
// 'class' => CustomCacheProvider::class, //The class is looked up in the container
159105
// ],
160-
'chain' => [
161-
'class' => ChainCache::class,
162-
'providers' => ['array', 'redis'], // you can use any provider listed above
163-
'namespace' => 'psr-container-doctrine', // will be applied to all providers in the chain
164-
],
165106
],
166107
'types' => [],
167108
'migrations' => [
@@ -223,6 +164,14 @@ public function wrap(DbalDriver $driver): DbalDriver
223164
}
224165
};
225166
},
167+
168+
FilesystemAdapter::class => static function (): FilesystemAdapter {
169+
return new FilesystemAdapter(
170+
'psr-container-doctrine',
171+
3600,
172+
__DIR__ . '/data/cache/DoctrineCache',
173+
);
174+
},
226175
],
227176
],
228177
];

psalm.xml.dist

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@
3030
</InternalClass>
3131
<DeprecatedClass>
3232
<errorLevel type="suppress">
33-
<referencedClass name="Doctrine\Common\Cache\ApcuCache"/>
34-
<referencedClass name="Doctrine\Common\Cache\ArrayCache"/>
35-
<referencedClass name="Doctrine\Common\Cache\Cache"/>
36-
<referencedClass name="Doctrine\Common\Cache\CacheProvider"/>
37-
<referencedClass name="Doctrine\Common\Cache\ChainCache"/>
38-
<referencedClass name="Doctrine\Common\Cache\FilesystemCache"/>
39-
<referencedClass name="Doctrine\Common\Cache\MemcachedCache"/>
40-
<referencedClass name="Doctrine\Common\Cache\PhpFileCache"/>
41-
<referencedClass name="Doctrine\Common\Cache\PredisCache"/>
42-
<referencedClass name="Doctrine\Common\Cache\RedisCache"/>
43-
<referencedClass name="Doctrine\Common\Cache\WinCacheCache"/>
44-
<referencedClass name="Doctrine\Common\Cache\ZendDataCache"/>
4533
<referencedClass name="Doctrine\Common\Annotations\CachedReader"/>
4634
<referencedClass name="Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver"/>
4735
<referencedClass name="Doctrine\Persistence\Mapping\Driver\AnnotationDriver"/>

src/Cache/NullCache.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Roave\PsrContainerDoctrine\Cache;
6+
7+
use Psr\Cache\CacheItemInterface;
8+
use Psr\Cache\CacheItemPoolInterface;
9+
10+
final class NullCache implements CacheItemPoolInterface
11+
{
12+
public function getItem(string $key): CacheItemInterface
13+
{
14+
return new NullCacheItem($key);
15+
}
16+
17+
/**
18+
* {@inheritDoc}
19+
*/
20+
public function getItems(array $keys = []): iterable
21+
{
22+
foreach ($keys as $key) {
23+
yield $key => $this->getItem($key);
24+
}
25+
}
26+
27+
public function hasItem(string $key): bool
28+
{
29+
return false;
30+
}
31+
32+
public function clear(): bool
33+
{
34+
return true;
35+
}
36+
37+
public function deleteItem(string $key): bool
38+
{
39+
return true;
40+
}
41+
42+
/**
43+
* {@inheritDoc}
44+
*/
45+
public function deleteItems(array $keys): bool
46+
{
47+
return true;
48+
}
49+
50+
public function save(CacheItemInterface $item): bool
51+
{
52+
return true;
53+
}
54+
55+
public function saveDeferred(CacheItemInterface $item): bool
56+
{
57+
return true;
58+
}
59+
60+
public function commit(): bool
61+
{
62+
return true;
63+
}
64+
}

src/Cache/NullCacheItem.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Roave\PsrContainerDoctrine\Cache;
6+
7+
use DateInterval;
8+
use DateTimeInterface;
9+
use Psr\Cache\CacheItemInterface;
10+
11+
final class NullCacheItem implements CacheItemInterface
12+
{
13+
public function __construct(
14+
private readonly string $key,
15+
) {
16+
}
17+
18+
public function getKey(): string
19+
{
20+
return $this->key;
21+
}
22+
23+
public function get(): mixed
24+
{
25+
return null;
26+
}
27+
28+
public function isHit(): bool
29+
{
30+
return false;
31+
}
32+
33+
public function set(mixed $value): static
34+
{
35+
return $this;
36+
}
37+
38+
public function expiresAt(DateTimeInterface|null $expiration): static
39+
{
40+
return $this;
41+
}
42+
43+
public function expiresAfter(int|DateInterval|null $time): static
44+
{
45+
return $this;
46+
}
47+
}

0 commit comments

Comments
 (0)