Skip to content

Commit 4418be1

Browse files
committed
feature #43362 [Cache] Split PdoAdapter into DoctrineDbalAdapter (GromNaN)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Cache] Split PdoAdapter into DoctrineDbalAdapter | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | Fix #42962 | License | MIT | Doc PR | symfony/symfony-docs#15903 Commits ------- db665be [Cache] Split PdoAdapter into DoctrineDbalAdapter
2 parents 732acf5 + db665be commit 4418be1

19 files changed

+984
-230
lines changed

UPGRADE-5.4.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Cache
55
-----
66

77
* Deprecate `DoctrineProvider` and `DoctrineAdapter` because these classes have been added to the `doctrine/cache` package
8+
* Deprecate usage of `PdoAdapter` with a `Doctrine\DBAL\Connection` or a DBAL URL. Use the new `DoctrineDbalAdapter` instead
89

910
Console
1011
-------

UPGRADE-6.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Cache
1515
-----
1616

1717
* Remove `DoctrineProvider` and `DoctrineAdapter` because these classes have been added to the `doctrine/cache` package
18+
* `PdoAdapter` does not accept `Doctrine\DBAL\Connection` or DBAL URL. Use the new `DoctrineDbalAdapter` instead
1819

1920
Config
2021
------

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"doctrine/cache": "^1.11|^2.0",
130130
"doctrine/collections": "~1.0",
131131
"doctrine/data-fixtures": "^1.1",
132-
"doctrine/dbal": "^2.13|^3.0",
132+
"doctrine/dbal": "^2.13.1|^3.0",
133133
"doctrine/orm": "^2.7.3",
134134
"guzzlehttp/promises": "^1.4",
135135
"masterminds/html5": "^2.6",
@@ -155,7 +155,7 @@
155155
"ext-psr": "<1.1|>=2",
156156
"async-aws/core": "<1.5",
157157
"doctrine/annotations": "<1.13.1",
158-
"doctrine/dbal": "<2.13",
158+
"doctrine/dbal": "<2.13.1",
159159
"egulias/email-validator": "~3.0.0",
160160
"masterminds/html5": "<2.6",
161161
"phpdocumentor/reflection-docblock": "<3.2.2",

src/Symfony/Bridge/Doctrine/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `DoctrineOpenTransactionLoggerMiddleware` to log when a transaction has been left open
8+
* Deprecate `PdoCacheAdapterDoctrineSchemaSubscriber` and add `DoctrineDbalCacheAdapterSchemaSubscriber` instead
89

910
5.3
1011
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\SchemaListener;
13+
14+
use Doctrine\Common\EventSubscriber;
15+
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
16+
use Doctrine\ORM\Tools\ToolEvents;
17+
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;
18+
19+
/**
20+
* Automatically adds the cache table needed for the DoctrineDbalAdapter of
21+
* the Cache component.
22+
*
23+
* @author Ryan Weaver <ryan@symfonycasts.com>
24+
*/
25+
final class DoctrineDbalCacheAdapterSchemaSubscriber implements EventSubscriber
26+
{
27+
private $dbalAdapters;
28+
29+
/**
30+
* @param iterable<mixed, DoctrineSchemaConfiguratorInterface> $dbalAdapters
31+
*/
32+
public function __construct(iterable $dbalAdapters)
33+
{
34+
$this->dbalAdapters = $dbalAdapters;
35+
}
36+
37+
public function postGenerateSchema(GenerateSchemaEventArgs $event): void
38+
{
39+
$dbalConnection = $event->getEntityManager()->getConnection();
40+
foreach ($this->dbalAdapters as $dbalAdapter) {
41+
$dbalAdapter->configureSchema($event->getSchema(), $dbalConnection);
42+
}
43+
}
44+
45+
public function getSubscribedEvents(): array
46+
{
47+
if (!class_exists(ToolEvents::class)) {
48+
return [];
49+
}
50+
51+
return [
52+
ToolEvents::postGenerateSchema,
53+
];
54+
}
55+
}

src/Symfony/Bridge/Doctrine/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriber.php

+4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
use Doctrine\ORM\Tools\ToolEvents;
1717
use Symfony\Component\Cache\Adapter\PdoAdapter;
1818

19+
trigger_deprecation('symfony/doctrine-bridge', '5.4', 'The "%s" class is deprecated, use "%s" instead.', PdoCacheAdapterDoctrineSchemaSubscriber::class, DoctrineDbalCacheAdapterSchemaSubscriber::class);
20+
1921
/**
2022
* Automatically adds the cache table needed for the PdoAdapter.
2123
*
2224
* @author Ryan Weaver <ryan@symfonycasts.com>
25+
*
26+
* @deprecated since symfony 5.4 use DoctrineDbalCacheAdapterSchemaSubscriber
2327
*/
2428
final class PdoCacheAdapterDoctrineSchemaSubscriber implements EventSubscriber
2529
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\SchemaListener;
13+
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Schema\Schema;
16+
use Doctrine\ORM\EntityManagerInterface;
17+
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
18+
use PHPUnit\Framework\TestCase;
19+
use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber;
20+
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;
21+
22+
class DoctrineDbalCacheAdapterSchemaSubscriberTest extends TestCase
23+
{
24+
public function testPostGenerateSchema()
25+
{
26+
$schema = new Schema();
27+
$dbalConnection = $this->createMock(Connection::class);
28+
$entityManager = $this->createMock(EntityManagerInterface::class);
29+
$entityManager->expects($this->once())
30+
->method('getConnection')
31+
->willReturn($dbalConnection);
32+
$event = new GenerateSchemaEventArgs($entityManager, $schema);
33+
34+
$pdoAdapter = $this->createMock(DoctrineSchemaConfiguratorInterface::class);
35+
$pdoAdapter->expects($this->once())
36+
->method('configureSchema')
37+
->with($schema, $dbalConnection);
38+
39+
$subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$pdoAdapter]);
40+
$subscriber->postGenerateSchema($event);
41+
}
42+
}

src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriberTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
2020
use Symfony\Component\Cache\Adapter\PdoAdapter;
2121

22+
/**
23+
* @group legacy
24+
*/
2225
class PdoCacheAdapterDoctrineSchemaSubscriberTest extends TestCase
2326
{
2427
public function testPostGenerateSchema()

src/Symfony/Bridge/Doctrine/composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require-dev": {
2929
"composer/package-versions-deprecated": "^1.8",
3030
"symfony/stopwatch": "^4.4|^5.0|^6.0",
31-
"symfony/cache": "^5.1|^6.0",
31+
"symfony/cache": "^5.4|^6.0",
3232
"symfony/config": "^4.4|^5.0|^6.0",
3333
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
3434
"symfony/form": "^5.1.3|^6.0",
@@ -47,14 +47,15 @@
4747
"doctrine/annotations": "^1.10.4",
4848
"doctrine/collections": "~1.0",
4949
"doctrine/data-fixtures": "^1.1",
50-
"doctrine/dbal": "^2.13|^3.0",
50+
"doctrine/dbal": "^2.13.1|^3.0",
5151
"doctrine/orm": "^2.7.3",
5252
"psr/log": "^1|^2|^3"
5353
},
5454
"conflict": {
55-
"doctrine/dbal": "<2.13",
55+
"doctrine/dbal": "<2.13.1",
5656
"doctrine/orm": "<2.7.3",
5757
"phpunit/phpunit": "<5.4.3",
58+
"symfony/cache": "<5.4",
5859
"symfony/dependency-injection": "<4.4",
5960
"symfony/form": "<5.1",
6061
"symfony/http-kernel": "<5",

0 commit comments

Comments
 (0)