Skip to content

Commit 818eae9

Browse files
authored
Make doctrine/cache optional (#6740)
| Q | A |------------- | ----------- | Type | improvement | Fixed issues | N/A #### Summary We'd like to flag the the doctrine/cache package as abandoned which means it needs to disappear from the list of mandatory dependencies of DBAL. In DBAL 3.9, the doctrine/cache classes are used for deprecated code paths only. Note: This change could break downstream projects if they rely on DBAL installing the Cache package for them.
1 parent d154c50 commit 818eae9

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

.github/workflows/continuous-integration.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ jobs:
4343
dependencies:
4444
- "highest"
4545
extension:
46+
- "sqlite3"
4647
- "pdo_sqlite"
4748
include:
4849
- os: "ubuntu-20.04"
4950
php-version: "7.4"
5051
dependencies: "lowest"
5152
extension: "pdo_sqlite"
5253
- os: "ubuntu-22.04"
53-
php-version: "7.4"
54-
dependencies: "highest"
54+
php-version: "8.4"
55+
dependencies: "minimal"
5556
extension: "sqlite3"
5657

5758
steps:
@@ -60,6 +61,10 @@ jobs:
6061
with:
6162
fetch-depth: 2
6263

64+
- name: "Remove optional dependencies"
65+
run: "composer remove --no-update --dev doctrine/cache"
66+
if: "${{ matrix.dependencies == 'minimal' }}"
67+
6368
- name: "Install PHP"
6469
uses: "shivammathur/setup-php@v2"
6570
with:
@@ -71,7 +76,7 @@ jobs:
7176
uses: "ramsey/composer-install@v3"
7277
with:
7378
composer-options: "--ignore-platform-req=php+"
74-
dependency-versions: "${{ matrix.dependencies }}"
79+
dependency-versions: "${{ matrix.dependencies == 'minimal' && 'highest' || matrix.dependencies }}"
7580

7681
- name: "Print SQLite version"
7782
run: >

UPGRADE.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ awareness about deprecated code.
66
- Use of our low-overhead runtime deprecation API, details:
77
https://github.com/doctrine/deprecations/
88

9+
# Upgrade to 3.10
10+
11+
The `doctrine/cache` package is now an optional dependency. If you are using the
12+
`Doctrine\DBAL\Cache` classes, you need to require the `doctrine/cache` package
13+
explicitly.
14+
915
# Upgrade to 3.8
1016

1117
## Deprecated lock-related `AbstractPlatform` methods

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
"require": {
3434
"php": "^7.4 || ^8.0",
3535
"composer-runtime-api": "^2",
36-
"doctrine/cache": "^1.11|^2.0",
3736
"doctrine/deprecations": "^0.5.3|^1",
3837
"doctrine/event-manager": "^1|^2",
3938
"psr/cache": "^1|^2|^3",
4039
"psr/log": "^1|^2|^3"
4140
},
4241
"require-dev": {
42+
"doctrine/cache": "^1.11|^2.0",
4343
"doctrine/coding-standard": "12.0.0",
4444
"fig/log-test": "^1",
4545
"jetbrains/phpstorm-stubs": "2023.1",
@@ -51,6 +51,9 @@
5151
"symfony/cache": "^5.4|^6.0|^7.0",
5252
"symfony/console": "^4.4|^5.4|^6.0|^7.0"
5353
},
54+
"conflict": {
55+
"doctrine/cache": "< 1.11"
56+
},
5457
"suggest": {
5558
"symfony/console": "For helpful console commands such as SQL execution and import of files."
5659
},

src/Cache/QueryCacheProfile.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use Doctrine\DBAL\Types\Type;
99
use Doctrine\Deprecations\Deprecation;
1010
use Psr\Cache\CacheItemPoolInterface;
11+
use RuntimeException;
1112
use TypeError;
1213

14+
use function class_exists;
1315
use function get_class;
1416
use function hash;
1517
use function serialize;
@@ -82,7 +84,19 @@ public function getResultCacheDriver()
8284
__METHOD__,
8385
);
8486

85-
return $this->resultCache !== null ? DoctrineProvider::wrap($this->resultCache) : null;
87+
if ($this->resultCache === null) {
88+
return null;
89+
}
90+
91+
if (! class_exists(DoctrineProvider::class)) {
92+
throw new RuntimeException(sprintf(
93+
'Calling %s() is not supported if the doctrine/cache package is not installed. '
94+
. 'Try running "composer require doctrine/cache" or migrate cache access to PSR-6.',
95+
__METHOD__,
96+
));
97+
}
98+
99+
return DoctrineProvider::wrap($this->resultCache);
86100
}
87101

88102
/** @return int */

src/Configuration.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
use Doctrine\DBAL\Schema\SchemaManagerFactory;
1111
use Doctrine\Deprecations\Deprecation;
1212
use Psr\Cache\CacheItemPoolInterface;
13+
use RuntimeException;
1314

15+
use function class_exists;
1416
use function func_num_args;
17+
use function interface_exists;
18+
use function sprintf;
1519

1620
/**
1721
* Configuration container for the Doctrine DBAL.
@@ -129,6 +133,14 @@ public function getResultCacheImpl(): ?Cache
129133
__METHOD__,
130134
);
131135

136+
if ($this->resultCache !== null && ! interface_exists(Cache::class)) {
137+
throw new RuntimeException(sprintf(
138+
'Calling %s() is not supported if the doctrine/cache package is not installed. '
139+
. 'Try running "composer require doctrine/cache" or migrate cache access to PSR-6.',
140+
__METHOD__,
141+
));
142+
}
143+
132144
return $this->resultCacheImpl;
133145
}
134146

@@ -137,8 +149,11 @@ public function getResultCacheImpl(): ?Cache
137149
*/
138150
public function setResultCache(CacheItemPoolInterface $cache): void
139151
{
140-
$this->resultCacheImpl = DoctrineProvider::wrap($cache);
141-
$this->resultCache = $cache;
152+
if (class_exists(DoctrineProvider::class)) {
153+
$this->resultCacheImpl = DoctrineProvider::wrap($cache);
154+
}
155+
156+
$this->resultCache = $cache;
142157
}
143158

144159
/**

tests/Connection/CachedQueryTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function testCachedQueryLegacy(): void
4040

4141
public function testCachedQueryLegacyWrapped(): void
4242
{
43+
if (! class_exists(DoctrineProvider::class)) {
44+
self::markTestSkipped('This test requires the doctrine/cache package.');
45+
}
46+
4347
$cache = new ArrayAdapter();
4448
$legacy = DoctrineProvider::wrap($cache);
4549
$this->assertCachedQueryIsExecutedOnceAndYieldsTheSameResult($legacy, __FUNCTION__);

0 commit comments

Comments
 (0)