Skip to content

[Cache] Split PdoAdapter into DoctrineDbalAdapter #43362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-5.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Cache
-----

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

Console
-------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Cache
-----

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

Config
------
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"doctrine/cache": "^1.11|^2.0",
"doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.13|^3.0",
"doctrine/dbal": "^2.13.1|^3.0",
"doctrine/orm": "^2.7.3",
"guzzlehttp/promises": "^1.4",
"masterminds/html5": "^2.6",
Expand All @@ -155,7 +155,7 @@
"ext-psr": "<1.1|>=2",
"async-aws/core": "<1.5",
"doctrine/annotations": "<1.13.1",
"doctrine/dbal": "<2.13",
"doctrine/dbal": "<2.13.1",
"egulias/email-validator": "~3.0.0",
"masterminds/html5": "<2.6",
"phpdocumentor/reflection-docblock": "<3.2.2",
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

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

5.3
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\SchemaListener;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Doctrine\ORM\Tools\ToolEvents;
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;

/**
* Automatically adds the cache table needed for the DoctrineDbalAdapter of
* the Cache component.
*
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
final class DoctrineDbalCacheAdapterSchemaSubscriber implements EventSubscriber
{
private $dbalAdapters;

/**
* @param iterable<mixed, DoctrineSchemaConfiguratorInterface> $dbalAdapters
*/
public function __construct(iterable $dbalAdapters)
{
$this->dbalAdapters = $dbalAdapters;
}

public function postGenerateSchema(GenerateSchemaEventArgs $event): void
{
$dbalConnection = $event->getEntityManager()->getConnection();
foreach ($this->dbalAdapters as $dbalAdapter) {
$dbalAdapter->configureSchema($event->getSchema(), $dbalConnection);
}
}

public function getSubscribedEvents(): array
{
if (!class_exists(ToolEvents::class)) {
return [];
}

return [
ToolEvents::postGenerateSchema,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
use Doctrine\ORM\Tools\ToolEvents;
use Symfony\Component\Cache\Adapter\PdoAdapter;

trigger_deprecation('symfony/doctrine-bridge', '5.4', 'The "%s" class is deprecated, use "%s" instead.', PdoCacheAdapterDoctrineSchemaSubscriber::class, DoctrineDbalCacheAdapterSchemaSubscriber::class);

/**
* Automatically adds the cache table needed for the PdoAdapter.
*
* @author Ryan Weaver <ryan@symfonycasts.com>
*
* @deprecated since symfony 5.4 use DoctrineDbalCacheAdapterSchemaSubscriber
*/
final class PdoCacheAdapterDoctrineSchemaSubscriber implements EventSubscriber
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\SchemaListener;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber;
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;

class DoctrineDbalCacheAdapterSchemaSubscriberTest extends TestCase
{
public function testPostGenerateSchema()
{
$schema = new Schema();
$dbalConnection = $this->createMock(Connection::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects($this->once())
->method('getConnection')
->willReturn($dbalConnection);
$event = new GenerateSchemaEventArgs($entityManager, $schema);

$pdoAdapter = $this->createMock(DoctrineSchemaConfiguratorInterface::class);
$pdoAdapter->expects($this->once())
->method('configureSchema')
->with($schema, $dbalConnection);

$subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$pdoAdapter]);
$subscriber->postGenerateSchema($event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
use Symfony\Component\Cache\Adapter\PdoAdapter;

/**
* @group legacy
*/
class PdoCacheAdapterDoctrineSchemaSubscriberTest extends TestCase
{
public function testPostGenerateSchema()
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require-dev": {
"composer/package-versions-deprecated": "^1.8",
"symfony/stopwatch": "^4.4|^5.0|^6.0",
"symfony/cache": "^5.1|^6.0",
"symfony/cache": "^5.4|^6.0",
"symfony/config": "^4.4|^5.0|^6.0",
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
"symfony/form": "^5.1.3|^6.0",
Expand All @@ -47,14 +47,15 @@
"doctrine/annotations": "^1.10.4",
"doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.13|^3.0",
"doctrine/dbal": "^2.13.1|^3.0",
"doctrine/orm": "^2.7.3",
"psr/log": "^1|^2|^3"
},
"conflict": {
"doctrine/dbal": "<2.13",
"doctrine/dbal": "<2.13.1",
"doctrine/orm": "<2.7.3",
"phpunit/phpunit": "<5.4.3",
"symfony/cache": "<5.4",
"symfony/dependency-injection": "<4.4",
"symfony/form": "<5.1",
"symfony/http-kernel": "<5",
Expand Down
Loading