8000 bug #44065 [FrameworkBundle] Add framework config for DBAL cache adap… · symfony/symfony@a8bee28 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8bee28

Browse files
committed
bug #44065 [FrameworkBundle] Add framework config for DBAL cache adapter (GromNaN)
This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Add framework config for DBAL cache adapter | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | doctrine/DoctrineBundle#1417 | License | MIT | Doc PR | - The framework configuration was missing from #43362. Additionnaly, the depreciation message on `PdoCacheAdapterDoctrineSchemaSubscriber` must be removed. This class needs to be used in 5.4 whenever a `PdoAdapter` is used, because it could have a DBAL connection and we need to keep the deprecated behavior. A depreciation message is already triggered in the `PdoAdapter` itself when it gets a DBAL connection. Commits ------- 672545d Add framework config for DBAL cache adapter
2 parents 8ca777b + 672545d commit a8bee28

14 files changed

+56
-46
lines changed

UPGRADE-5.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ FrameworkBundle
3737
* Deprecate the public `profiler` service to private
3838
* Deprecate `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead
3939
* Deprecate the `cache.adapter.doctrine` service: The Doctrine Cache library is deprecated. Either switch to Symfony Cache or use the PSR-6 adapters provided by Doctrine Cache.
40+
* In `framework.cache` configuration, using `cache.adapter.pdo` adapter with a Doctrine DBAL connection is deprecated, use `cache.adapter.doctrine_dbal` instead.
4041

4142
HttpKernel
4243
----------

UPGRADE-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ FrameworkBundle
109109
* Remove the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead
110110
* Remove `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead
111111
* Deprecate the `cache.adapter.doctrine` service: The Doctrine Cache library is deprecated. Either switch to Symfony Cache or use the PSR-6 adapters provided by Doctrine Cache.
112+
* In `framework.cache` configuration, using the `cache.adapter.pdo` with a Doctrine DBAL connection is no longer supported, use `cache.adapter.doctrine_dbal` instead.
112113

113114
HttpFoundation
114115
--------------

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Doctrine\Common\EventSubscriber;
1515
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
1616
use Doctrine\ORM\Tools\ToolEvents;
17-
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;
17+
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
1818

1919
/**
2020
* Automatically adds the cache table needed for the DoctrineDbalAdapter of
@@ -27,7 +27,7 @@ final class DoctrineDbalCacheAdapterSchemaSubscriber implements EventSubscriber
2727
private $dbalAdapters;
2828

2929
/**
30-
* @param iterable<mixed, DoctrineSchemaConfiguratorInterface> $dbalAdapters
30+
* @param iterable<mixed, DoctrineDbalAdapter> $dbalAdapters
3131
*/
3232
public function __construct(iterable $dbalAdapters)
3333
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
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-
2119
/**
2220
* Automatically adds the cache table needed for the PdoAdapter.
2321
*
@@ -41,6 +39,10 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event): void
4139
{
4240
$dbalConnectio 10000 n = $event->getEntityManager()->getConnection();
4341
foreach ($this->pdoAdapters as $pdoAdapter) {
42+
if (PdoAdapter::class !== \get_class($pdoAdapter)) {
43+
trigger_deprecation('symfony/doctrine-bridge', '5.4', 'The "%s" class is deprecated, use "%s" instead.', self::class, DoctrineDbalCacheAdapterSchemaSubscriber::class);
44+
}
45+
4446
$pdoAdapter->configureSchema($event->getSchema(), $dbalConnection);
4547
}
4648
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
1818
use PHPUnit\Framework\TestCase;
1919
use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber;
20-
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;
20+
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
2121

2222
class DoctrineDbalCacheAdapterSchemaSubscriberTest extends TestCase
2323
{
@@ -29,14 +29,15 @@ public function testPostGenerateSchema()
2929
$entityManager->expects($this->once())
3030
->method('getConnection')
3131
->willReturn($dbalConnection);
32+
3233
$event = new GenerateSchemaEventArgs($entityManager, $schema);
3334

34-
$pdoAdapter = $this->createMock(DoctrineSchemaConfiguratorInterface::class);
35-
$pdoAdapter->expects($this->once())
35+
$dbalAdapter = $this->createMock(DoctrineDbalAdapter::class);
36+
$dbalAdapter->expects($this->once())
3637
->method('configureSchema')
3738
->with($schema, $dbalConnection);
3839

39-
$subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$pdoAdapter]);
40+
$subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$dbalAdapter]);
4041
$subscriber->postGenerateSchema($event);
4142
}
4243
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,33 @@
1717
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
1818
use PHPUnit\Framework\TestCase;
1919
use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
20+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2021
use Symfony\Component\Cache\Adapter\PdoAdapter;
2122

2223
/**
2324
* @group legacy
2425
*/
2526
class PdoCacheAdapterDoctrineSchemaSubscriberTest extends TestCase
2627
{
28+
use ExpectDeprecationTrait;
29+
2730
public function testPostGenerateSchema()
2831
{
2932
$schema = new Schema();
3033
$dbalConnection = $this->createMock(Connection::class);
3134
$entityManager = $this->createMock(EntityManagerInterface::class);
32-
$entityManager->expects($this->once())
35+
$entityManager->expects($this->any())
3336
->method('getConnection')
3437
->willReturn($dbalConnection);
38+
3539
$event = new GenerateSchemaEventArgs($entityManager, $schema);
3640

3741
$pdoAdapter = $this->createMock(PdoAdapter::class);
3842
$pdoAdapter->expects($this->once())
3943
->method('configureSchema')
40-
->with($schema, $dbalConnection);
44+
->with($event->getSchema(), $event->getEntityManager()->getConnection());
45+
46+
$this->expectDeprecation('Since symfony/doctrine-bridge 5.4: The "Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber" class is deprecated, use "Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber" instead.');
4147

4248
$subscriber = new PdoCacheAdapterDoctrineSchemaSubscriber([$pdoAdapter]);
4349
$subscriber->postGenerateSchema($event);

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CHANGELOG
2121
* Add support for `statusCode` default parameter when loading a template directly from route using the `Symfony\Bundle\FrameworkBundle\Controller\TemplateController` controller
2222
* Deprecate `translation:update` command, use `translation:extract` instead
2323
* Add `PhpStanExtractor` support for the PropertyInfo component
24+
* Add `cache.adapter.doctrine_dbal` service to replace `cache.adapter.pdo` when a Doctrine DBAL connection is used.
2425

2526
5.3
2627
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBe
10771077
->scalarNode('default_psr6_provider')->end()
10781078
->scalarNode('default_redis_provider')->defaultValue('redis://localhost')->end()
10791079
->scalarNode('default_memcached_provider')->defaultValue('memcached://localhost')->end()
1080+
->scalarNode('default_doctrine_dbal_provider')->defaultValue('database_connection')->end()
10801081
->scalarNode('default_pdo_provider')->defaultValue($willBeAvailable('doctrine/dbal', Connection::class) ? 'database_connection' : null)->end()
10811082
->arrayNode('pools')
10821083
->useAttributeAsKey('name')

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
use Symfony\Component\Cache\Adapter\AdapterInterface;
3535
use Symfony\Component\Cache\Adapter\ArrayAdapter;
3636
use Symfony\Component\Cache\Adapter\ChainAdapter;
37+
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
38+
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
3739
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
3840
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
3941
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
@@ -2159,6 +2161,14 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
21592161
$container->removeDefinition('cache.default_marshaller');
21602162
}
21612163

2164+
if (!class_exists(DoctrineAdapter::class)) {
2165+
$container->removeDefinition('cache.adapter.doctrine');
2166+
}
2167+
2168+
if (!class_exists(DoctrineDbalAdapter::class)) {
2169+
$container->removeDefinition('cache.adapter.doctrine_dbal');
2170+
}
2171+
21622172
$version = new Parameter('container.build_id');
21632173
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
21642174
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
@@ -2171,7 +2181,7 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
21712181
// Inline any env vars referenced in the parameter
21722182
$container->setParameter('cache.prefix.seed', $container->resolveEnvPlaceholders($container->getParameter('cache.prefix.seed'), true));
21732183
}
2174-
foreach (['doctrine', 'psr6', 'redis', 'memcached', 'pdo'] as $name) {
2184+
foreach (['doctrine', 'psr6', 'redis', 'memcached', 'doctrine_dbal', 'pdo'] as $name) {
21752185
if (isset($config[$name = 'default_'.$name.'_provider'])) {
21762186
$container->setAlias('cache.'.$name, new Alias(CachePoolPass::getServiceProvider($container, $config[$name]), false));
21772187
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Cache\Adapter\ApcuAdapter;
1818
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1919
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
20+
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
2021
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2122
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
2223
use Symfony\Component\Cache\Adapter\PdoAdapter;
@@ -93,10 +94,8 @@
9394
->call('setLogger', [service('logger')->ignoreOnInvalid()])
9495
->tag('cache.pool', ['clearer' => 'cache.default_clearer', 'reset' => 'reset'])
9596
->tag('monolog.logger', ['channel' => 'cache'])
96-
;
9797

98-
if (class_exists(DoctrineAdapter::class)) {
99-
$container->services()->set('cache.adapter.doctrine', DoctrineAdapter::class)
98+
->set('cache.adapter.doctrine', DoctrineAdapter::class)
10099
->abstract()
101100
->args([
102101
abstract_arg('Doctrine provider service'),
@@ -110,11 +109,8 @@
110109
'reset' => 'reset',
111110
])
112111
->tag('monolog.logger', ['channel' => 'cache'])
113-
->deprecate('symfony/framework-bundle', '5.4', 'The abstract service "%service_id%" is deprecated.')
114-
;
115-
}
112+
->deprecate('symfony/framework-bundle', '5.4', 'The "%service_id%" service inherits from "cache.adapter.doctrine" which is deprecated.')
116113

117-
$container->services()
118114
->set('cache.adapter.filesystem', FilesystemAdapter::class)
119115
->abstract()
120116
->args([
@@ -188,6 +184,23 @@
188184
])
189185
->tag('monolog.logger', ['channel' => 'cache'])
190186

187+
->set('cache.adapter.doctrine_dbal', DoctrineDbalAdapter::class)
188+
->abstract()
189+
->args([
190+
abstract_arg('DBAL connection service'),
191+
'', // namespace
192+
0, // default lifetime
193+
[], // table options
194+
service('cache.default_marshaller')->ignoreOnInvalid(),
195+
])
196+
8000 ->call('setLogger', [service('logger')->ignoreOnInvalid()])
197+
->tag('cache.pool', [
198+
'provider' => 'cache.default_doctrine_dbal_provider',
199+
'clearer' => 'cache.default_clearer',
200+
'reset' => 'reset',
201+
])
202+
->tag('monolog.logger', ['channel' => 'cache'])
203+
191204
->set('cache.adapter.pdo', PdoAdapter::class)
192205
->abstract()
193206
->args([

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ protected static function getBundleDefaultConfig()
504504
'directory' => '%kernel.cache_dir%/pools/app',
505505
'default_redis_provider' => 'redis://localhost',
506506
'default_memcached_provider' => 'memcached://localhost',
507+
'default_doctrine_dbal_provider' => 'database_connection',
507508
'default_pdo_provider' => ContainerBuilder::willBeAvailable('doctrine/dbal', Connection::class, ['symfony/framework-bundle']) ? 'database_connection' : null,
508509
'prefix_seed' => '_%kernel.project_dir%.%kernel.container_class%',
509510
],

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
2424
use Symfony\Component\Cache\PruneableInterface;
2525

26-
final class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface, DoctrineSchemaConfiguratorInterface
26+
class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface
2727
{
2828
protected $maxIdLength = 255;
2929

src/Symfony/Component/Cache/Adapter/DoctrineSchemaConfiguratorInterface.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ final class LockRegistry
4343
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'CouchbaseCollectionAdapter.php',
4444
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'DoctrineAdapter.php',
4545
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'DoctrineDbalAdapter.php',
46-
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'DoctrineSchemaConfiguratorInterface.php',
4746
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'FilesystemAdapter.php',
4847
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'FilesystemTagAwareAdapter.php',
4948
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'MemcachedAdapter.php',

0 commit comments

Comments
 (0)
0