Skip to content

Commit

Permalink
Backport the doctrine-cache-bundle changes (see contao#2534)
Browse files Browse the repository at this point in the history
Description
-----------

Backports the changes from contao#1916 to Contao 4.9 to make it compatible with PHP 8 (see contao#2263).

Commits
-------

ba9d21f Backport the doctrine-cache-bundle changes
d1103e9 CS
  • Loading branch information
leofeyer committed Dec 3, 2020
1 parent 1cc3754 commit 67c7b18
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 47 deletions.
1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -49,7 +49,6 @@
"contao/manager-plugin": "^2.6.2",
"doctrine/dbal": "^2.10",
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/doctrine-cache-bundle": "^1.3.1",
"doctrine/orm": "^2.6.3",
"dragonmantank/cron-expression": "^2.3",
"friendsofsymfony/http-cache": "^2.6",
Expand Down
1 change: 0 additions & 1 deletion core-bundle/composer.json
Expand Up @@ -48,7 +48,6 @@
"contao/imagine-svg": "^0.2.3 || ^1.0",
"doctrine/dbal": "^2.10",
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/doctrine-cache-bundle": "^1.3.1",
"doctrine/orm": "^2.6.3",
"dragonmantank/cron-expression": "^2.3",
"friendsofsymfony/http-cache": "^2.6",
Expand Down
2 changes: 0 additions & 2 deletions core-bundle/src/ContaoManager/Plugin.php
Expand Up @@ -18,7 +18,6 @@
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Knp\Bundle\TimeBundle\KnpTimeBundle;
use Lexik\Bundle\MaintenanceBundle\LexikMaintenanceBundle;
Expand Down Expand Up @@ -59,7 +58,6 @@ public function getBundles(ParserInterface $parser): array
MonologBundle::class,
SwiftmailerBundle::class,
DoctrineBundle::class,
DoctrineCacheBundle::class,
KnpMenuBundle::class,
KnpTimeBundle::class,
LexikMaintenanceBundle::class,
Expand Down
2 changes: 0 additions & 2 deletions core-bundle/tests/ContaoManager/PluginTest.php
Expand Up @@ -17,7 +17,6 @@
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\DelegatingParser;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Knp\Bundle\TimeBundle\KnpTimeBundle;
use Lexik\Bundle\MaintenanceBundle\LexikMaintenanceBundle;
Expand Down Expand Up @@ -76,7 +75,6 @@ public function testReturnsTheBundles(): void
$this->assertSame(
[
DoctrineBundle::class,
DoctrineCacheBundle::class,
KnpMenuBundle::class,
KnpTimeBundle::class,
LexikMaintenanceBundle::class,
Expand Down
2 changes: 1 addition & 1 deletion manager-bundle/composer.json
Expand Up @@ -22,13 +22,13 @@
"contao/manager-plugin": "^2.4",
"doctrine/dbal": "^2.10",
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/doctrine-cache-bundle": "^1.3.1",
"friendsofsymfony/http-cache": "^2.6",
"friendsofsymfony/http-cache-bundle": "^2.6",
"lexik/maintenance-bundle": "^2.1.3",
"nelmio/cors-bundle": "^1.5.3 || ^2.0.1",
"nelmio/security-bundle": "^2.2",
"ocramius/proxy-manager": "^2.1",
"symfony/cache": "4.4.*",
"symfony/config": "4.4.*",
"symfony/console": "4.4.*",
"symfony/debug": "4.4.*",
Expand Down
2 changes: 0 additions & 2 deletions manager-bundle/src/ContaoManager/Plugin.php
Expand Up @@ -31,7 +31,6 @@
use Contao\ManagerPlugin\Dependency\DependentPluginInterface;
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception\DriverException;
use FOS\HttpCacheBundle\FOSHttpCacheBundle;
Expand Down Expand Up @@ -96,7 +95,6 @@ public function getBundles(ParserInterface $parser)
BundleConfig::create(MonologBundle::class),
BundleConfig::create(SwiftmailerBundle::class),
BundleConfig::create(DoctrineBundle::class),
BundleConfig::create(DoctrineCacheBundle::class),
BundleConfig::create(LexikMaintenanceBundle::class),
BundleConfig::create(NelmioCorsBundle::class),
BundleConfig::create(NelmioSecurityBundle::class),
Expand Down
33 changes: 12 additions & 21 deletions manager-bundle/src/Resources/skeleton/config/config.yml
@@ -1,6 +1,7 @@
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
Expand All @@ -24,6 +25,12 @@ framework:
handler_id: ~
cookie_secure: auto
fragments: { path: /_fragment }
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system

# Contao configuration
contao:
Expand Down Expand Up @@ -57,29 +64,13 @@ doctrine:
naming_strategy: doctrine.orm.naming_strategy.default
metadata_cache_driver:
type: service
id: doctrine_cache.providers.doctrine_metadata_cache
result_cache_driver:
type: service
id: doctrine_cache.providers.doctrine_result_cache
id: app.doctrine_system_cache_provider
query_cache_driver:
type: service
id: doctrine_cache.providers.doctrine_query_cache

# Doctrine cache configuration
doctrine_cache:
providers:
doctrine_metadata_cache:
file_system:
extension: .cache
directory: '%kernel.cache_dir%/doctrine/metadata'
doctrine_result_cache:
file_system:
extension: .cache
directory: '%kernel.cache_dir%/doctrine/result'
doctrine_query_cache:
file_system:
extension: .cache
directory: '%kernel.cache_dir%/doctrine/query'
id: app.doctrine_system_cache_provider
result_cache_driver:
type: service
id: app.doctrine_result_cache_provider

# SwiftMailer configuration
swiftmailer:
Expand Down
10 changes: 10 additions & 0 deletions manager-bundle/src/Resources/skeleton/config/services.yml
@@ -0,0 +1,10 @@
services:
app.doctrine_result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
arguments:
- '@doctrine.result_cache_pool'

app.doctrine_system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
arguments:
- '@doctrine.system_cache_pool'
29 changes: 12 additions & 17 deletions manager-bundle/tests/ContaoManager/PluginTest.php
Expand Up @@ -22,7 +22,6 @@
use Contao\ManagerPlugin\PluginLoader;
use Contao\TestCase\ContaoTestCase;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle;
use Doctrine\DBAL\Connection;
use FOS\HttpCacheBundle\FOSHttpCacheBundle;
use Lexik\Bundle\MaintenanceBundle\LexikMaintenanceBundle;
Expand Down Expand Up @@ -84,7 +83,7 @@ public function testReturnsTheBundles(): void
/** @var array<BundleConfig> $bundles */
$bundles = $plugin->getBundles(new DelegatingParser());

$this->assertCount(14, $bundles);
$this->assertCount(13, $bundles);

$this->assertSame(FrameworkBundle::class, $bundles[0]->getName());
$this->assertSame([], $bundles[0]->getReplace());
Expand All @@ -110,39 +109,35 @@ public function testReturnsTheBundles(): void
$this->assertSame([], $bundles[5]->getReplace());
$this->assertSame([], $bundles[5]->getLoadAfter());

$this->assertSame(DoctrineCacheBundle::class, $bundles[6]->getName());
$this->assertSame(LexikMaintenanceBundle::class, $bundles[6]->getName());
$this->assertSame([], $bundles[6]->getReplace());
$this->assertSame([], $bundles[6]->getLoadAfter());

$this->assertSame(LexikMaintenanceBundle::class, $bundles[7]->getName());
$this->assertSame(NelmioCorsBundle::class, $bundles[7]->getName());
$this->assertSame([], $bundles[7]->getReplace());
$this->assertSame([], $bundles[7]->getLoadAfter());

$this->assertSame(NelmioCorsBundle::class, $bundles[8]->getName());
$this->assertSame(NelmioSecurityBundle::class, $bundles[8]->getName());
$this->assertSame([], $bundles[8]->getReplace());
$this->assertSame([], $bundles[8]->getLoadAfter());

$this->assertSame(NelmioSecurityBundle::class, $bundles[9]->getName());
$this->assertSame(FOSHttpCacheBundle::class, $bundles[9]->getName());
$this->assertSame([], $bundles[9]->getReplace());
$this->assertSame([], $bundles[9]->getLoadAfter());

$this->assertSame(FOSHttpCacheBundle::class, $bundles[10]->getName());
$this->assertSame(ContaoManagerBundle::class, $bundles[10]->getName());
$this->assertSame([], $bundles[10]->getReplace());
$this->assertSame([], $bundles[10]->getLoadAfter());
$this->assertSame([ContaoCoreBundle::class], $bundles[10]->getLoadAfter());

$this->assertSame(ContaoManagerBundle::class, $bundles[11]->getName());
$this->assertSame(DebugBundle::class, $bundles[11]->getName());
$this->assertSame([], $bundles[11]->getReplace());
$this->assertSame([ContaoCoreBundle::class], $bundles[11]->getLoadAfter());
$this->assertSame([], $bundles[11]->getLoadAfter());
$this->assertFalse($bundles[11]->loadInProduction());

$this->assertSame(DebugBundle::class, $bundles[12]->getName());
$this->assertSame(WebProfilerBundle::class, $bundles[12]->getName());
$this->assertSame([], $bundles[12]->getReplace());
$this->assertSame([], $bundles[12]->getLoadAfter());
$this->assertFalse($bundles[12]->loadInProduction());

$this->assertSame(WebProfilerBundle::class, $bundles[13]->getName());
$this->assertSame([], $bundles[13]->getReplace());
$this->assertSame([], $bundles[13]->getLoadAfter());
$this->assertFalse($bundles[13]->loadInProduction());
}

public function testRegistersModuleBundles(): void
Expand All @@ -167,7 +162,7 @@ static function ($resource): array {
$plugin = new Plugin();
$configs = $plugin->getBundles($parser);

$this->assertCount(16, $configs);
$this->assertCount(15, $configs);
$this->assertContains('foo1', $configs);
$this->assertContains('foo2', $configs);
$this->assertNotContains('foo3', $configs);
Expand Down

0 comments on commit 67c7b18

Please sign in to comment.