Skip to content

Commit dccbbe3

Browse files
author
Yevhen Vilkhovchenko
committed
Bump doctrine/cache:^2.0
1. Dropped Cache implementations (assume third party PRS-6|PSR-16 implementations will be used) force users change "doctrine.configuration.{$entityManagerName}" configs for: - 'metadata_cache' - 'query_cache' - 'result_cache' - 'hydration_cache' cause no 'array' implementation. This also cause drop instantiation logic CacheFactory, so no more effect from "doctrine.cache.{$cache}" configs: - 'directory' for FilesystemCache::__construct() (same for PhpFileCache) - 'providers' - for ChainCache - 'instance' - for setter injections into MemcachedCache and RedisCache, and PredisCache::__construct() left 'class' support still treat either as containerId to be fetched or as className to be instantiated 2. Left 'array' and 'filesystem' caches in full-config.php as example how to migrate to symfony/cache
1 parent c49d70f commit dccbbe3

File tree

6 files changed

+115
-340
lines changed

6 files changed

+115
-340
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": "~8.1.0 || ~8.2.0",
2020
"doctrine/annotations": "^1.14.2",
21-
"doctrine/cache": "^1.13.0",
21+
"doctrine/cache": "^2.0",
2222
"doctrine/common": "^3.4.3",
2323
"doctrine/dbal": "^3.5.2",
2424
"doctrine/event-manager": "^1.2.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/full-config.php

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,23 @@
33
declare(strict_types=1);
44

55
use App\Doctrine\CustomCacheProvider;
6-
use Doctrine\Common\Cache\ApcuCache;
7-
use Doctrine\Common\Cache\ArrayCache;
8-
use Doctrine\Common\Cache\ChainCache;
9-
use Doctrine\Common\Cache\FilesystemCache;
10-
use Doctrine\Common\Cache\MemcacheCache;
11-
use Doctrine\Common\Cache\MemcachedCache;
12-
use Doctrine\Common\Cache\PhpFileCache;
13-
use Doctrine\Common\Cache\PredisCache;
14-
use Doctrine\Common\Cache\RedisCache;
15-
use Doctrine\Common\Cache\WinCacheCache;
16-
use Doctrine\Common\Cache\XcacheCache;
17-
use Doctrine\Common\Cache\ZendDataCache;
186
use Doctrine\DBAL\Driver\PDOMySql\Driver;
197
use Doctrine\Migrations\Configuration\Migration\ConfigurationLoader;
208
use Doctrine\Migrations\DependencyFactory;
219
use Doctrine\Migrations\Tools\Console\Command;
10+
use Psr\Container\ContainerInterface;
2211
use Roave\PsrContainerDoctrine\ConfigurationLoaderFactory;
2312
use Roave\PsrContainerDoctrine\Migrations\CommandFactory;
2413
use Roave\PsrContainerDoctrine\Migrations\DependencyFactoryFactory;
14+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
15+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2516

2617
return [
2718
'doctrine' => [
2819
'configuration' => [
2920
'orm_default' => [
3021
'result_cache' => 'array',
31-
'metadata_cache' => 'array',
22+
'metadata_cache' => 'filesystem',
3223
'query_cache' => 'array',
3324
'hydration_cache' => 'array',
3425
'driver' => 'orm_default', // Actually defaults to the configuration config key, not hard-coded
@@ -100,64 +91,17 @@
10091
],
10192
],
10293
'cache' => [
103-
'apcu' => [
104-
'class' => ApcuCache::class,
105-
'namespace' => 'psr-container-doctrine',
106-
],
10794
'array' => [
108-
'class' => ArrayCache::class,
109-
'namespace' => 'psr-container-doctrine',
95+
'class' => ArrayAdapter::class,
11096
],
11197
'filesystem' => [
112-
'class' => FilesystemCache::class,
113-
'directory' => 'data/cache/DoctrineCache',
114-
'namespace' => 'psr-container-doctrine',
115-
],
116-
'memcache' => [
117-
'class' => MemcacheCache::class,
118-
'instance' => 'my_memcache_alias',
119-
'namespace' => 'psr-container-doctrine',
120-
],
121-
'memcached' => [
122-
'class' => MemcachedCache::class,
123-
'instance' => 'my_memcached_alias',
124-
'namespace' => 'psr-container-doctrine',
125-
],
126-
'phpfile' => [
127-
'class' => PhpFileCache::class,
98+
'class' => FilesystemAdapter::class,
12899
'directory' => 'data/cache/DoctrineCache',
129100
'namespace' => 'psr-container-doctrine',
130101
],
131-
'predis' => [
132-
'class' => PredisCache::class,
133-
'instance' => 'my_predis_alias',
134-
'namespace' => 'psr-container-doctrine',
135-
],
136-
'redis' => [
137-
'class' => RedisCache::class,
138-
'instance' => 'my_redis_alias',
139-
'namespace' => 'psr-container-doctrine',
140-
],
141-
'wincache' => [
142-
'class' => WinCacheCache::class,
143-
'namespace' => 'psr-container-doctrine',
144-
],
145-
'xcache' => [
146-
'class' => XcacheCache::class,
147-
'namespace' => 'psr-container-doctrine',
148-
],
149-
'zenddata' => [
150-
'class' => ZendDataCache::class,
151-
'namespace' => 'psr-container-doctrine',
152-
],
153102
'my_cache_provider' => [
154103
'class' => CustomCacheProvider::class, //The class is looked up in the container
155104
],
156-
'chain' => [
157-
'class' => ChainCache::class,
158-
'providers' => ['array', 'redis'], // you can use any provider listed above
159-
'namespace' => 'psr-container-doctrine', // will be applied to all providers in the chain
160-
],
161105
],
162106
'types' => [],
163107
'migrations' => [
@@ -193,6 +137,16 @@
193137

194138
DependencyFactory::class => DependencyFactoryFactory::class,
195139
ConfigurationLoader::class => ConfigurationLoaderFactory::class,
140+
141+
FilesystemAdapter::class => static function (ContainerInterface $container): FilesystemAdapter {
142+
$config = $container->get('config');
143+
$params = $config['doctrine']['cache']['filesystem'];
144+
145+
return new FilesystemAdapter(
146+
namespace: $params['namespace'],
147+
directory: $params['directory'],
148+
);
149+
},
196150
],
197151
],
198152
];

src/CacheFactory.php

Lines changed: 2 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,13 @@
44

55
namespace Roave\PsrContainerDoctrine;
66

7-
use Doctrine\Common\Cache\ApcuCache;
8-
use Doctrine\Common\Cache\ArrayCache;
97
use Doctrine\Common\Cache\Cache;
108
use Doctrine\Common\Cache\CacheProvider;
11-
use Doctrine\Common\Cache\ChainCache;
12-
use Doctrine\Common\Cache\FilesystemCache;
13-
use Doctrine\Common\Cache\MemcachedCache;
14-
use Doctrine\Common\Cache\PhpFileCache;
15-
use Doctrine\Common\Cache\PredisCache;
16-
use Doctrine\Common\Cache\RedisCache;
17-
use Doctrine\Common\Cache\WinCacheCache;
18-
use Doctrine\Common\Cache\ZendDataCache;
199
use Psr\Cache\CacheItemPoolInterface;
2010
use Psr\Container\ContainerInterface;
2111
use Roave\PsrContainerDoctrine\Exception\OutOfBoundsException;
2212

2313
use function array_key_exists;
24-
use function array_map;
25-
use function assert;
26-
use function is_array;
27-
use function is_string;
2814

2915
/**
3016
* @method Cache|CacheItemPoolInterface __invoke(ContainerInterface $container)
@@ -42,44 +28,7 @@ protected function createWithConfig(ContainerInterface $container, string $confi
4228
throw OutOfBoundsException::forMissingConfigKey('class');
4329
}
4430

45-
$instance = null;
46-
47-
if (array_key_exists('instance', $config)) {
48-
$instance = is_string($config['instance']) ? $container->get($config['instance']) : $config['instance'];
49-
}
50-
51-
switch ($config['class']) {
52-
case FilesystemCache::class:
53-
case PhpFileCache::class:
54-
$cache = new $config['class']($config['directory']);
55-
break;
56-
57-
case PredisCache::class:
58-
assert($instance !== null);
59-
$cache = new PredisCache($instance);
60-
break;
61-
62-
case ChainCache::class:
63-
$providers = array_map(
64-
function ($provider) use ($container): CacheProvider {
65-
return $this->createWithConfig($container, $provider);
66-
},
67-
is_array($config['providers']) ? $config['providers'] : []
68-
);
69-
$cache = new ChainCache($providers);
70-
break;
71-
72-
default:
73-
$cache = $container->has($config['class']) ? $container->get($config['class']) : new $config['class']();
74-
}
75-
76-
if ($cache instanceof MemcachedCache) {
77-
assert($instance !== null);
78-
$cache->setMemcached($instance);
79-
} elseif ($cache instanceof RedisCache) {
80-
assert($instance !== null);
81-
$cache->setRedis($instance);
82-
}
31+
$cache = $container->has($config['class']) ? $container->get($config['class']) : new $config['class']();
8332

8433
if ($cache instanceof CacheProvider && array_key_exists('namespace', $config)) {
8534
$cache->setNamespace($config['namespace']);
@@ -93,75 +42,6 @@ function ($provider) use ($container): CacheProvider {
9342
*/
9443
protected function getDefaultConfig(string $configKey): array
9544
{
96-
switch ($configKey) {
97-
case 'apcu':
98-
return [
99-
'class' => ApcuCache::class,
100-
'namespace' => 'psr-container-doctrine',
101-
];
102-
103-
case 'array':
104-
return [
105-
'class' => ArrayCache::class,
106-
'namespace' => 'psr-container-doctrine',
107-
];
108-
109-
case 'filesystem':
110-
return [
111-
'class' => FilesystemCache::class,
112-
'directory' => 'data/cache/DoctrineCache',
113-
'namespace' => 'psr-container-doctrine',
114-
];
115-
116-
case 'memcached':
117-
return [
118-
'class' => MemcachedCache::class,
119-
'instance' => 'my_memcached_alias',
120-
'namespace' => 'psr-container-doctrine',
121-
];
122-
123-
case 'phpfile':
124-
return [
125-
'class' => PhpFileCache::class,
126-
'directory' => 'data/cache/DoctrineCache',
127-
'namespace' => 'psr-container-doctrine',
128-
];
129-
130-
case 'predis':
131-
return [
132-
'class' => PredisCache::class,
133-
'instance' => 'my_predis_alias',
134-
'namespace' => 'psr-container-doctrine',
135-
];
136-
137-
case 'redis':
138-
return [
139-
'class' => RedisCache::class,
140-
'instance' => 'my_redis_alias',
141-
'namespace' => 'psr-container-doctrine',
142-
];
143-
144-
case 'wincache':
145-
return [
146-
'class' => WinCacheCache::class,
147-
'namespace' => 'psr-container-doctrine',
148-
];
149-
150-
case 'zenddata':
151-
return [
152-
'class' => ZendDataCache::class,
153-
'namespace' => 'psr-container-doctrine',
154-
];
155-
156-
case 'chain':
157-
return [
158-
'class' => ChainCache::class,
159-
'namespace' => 'psr-container-doctrine',
160-
'providers' => [],
161-
];
162-
163-
default:
164-
return [];
165-
}
45+
return [];
16646
}
16747
}

0 commit comments

Comments
 (0)