Skip to content

Commit

Permalink
Merge branch '1.12.x' into 2.0.x
Browse files Browse the repository at this point in the history
* 1.12.x:
  Fix: use array adapter cache pools by default
  Use symfony/flex to lock Symfony dependencies to the same version
  • Loading branch information
alcaeus committed Nov 27, 2019
2 parents 8282627 + 1035bdd commit 6e2923b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
24 changes: 11 additions & 13 deletions DependencyInjection/DoctrineExtension.php
Expand Up @@ -12,6 +12,7 @@
use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
Expand Down Expand Up @@ -723,7 +724,7 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
break;

case 'pool':
$serviceId = $this->createPoolCacheDefinition($container, $cacheDriver['pool'] ?? $this->getPoolNameForCacheDriver($cacheName));
$serviceId = $this->createPoolCacheDefinition($container, $cacheDriver['pool'] ?? $this->createArrayAdapterCachePool($container, $objectManagerName, $cacheName));
break;

case 'provider':
Expand Down Expand Up @@ -847,11 +848,7 @@ private function loadMessengerServices(ContainerBuilder $container) : void

private function createPoolCacheDefinition(ContainerBuilder $container, string $poolName) : string
{
if (! class_exists(DoctrineProvider::class)) {
throw new LogicException('Using the "pool" cache type is only supported when symfony/cache is installed.');
}

$serviceId = sprintf('doctrine.orm.cache.pool.%s', $poolName);
$serviceId = sprintf('doctrine.orm.cache.provider.%s', $poolName);

$definition = $container->register($serviceId, DoctrineProvider::class);
$definition->addArgument(new Reference($poolName));
Expand All @@ -860,13 +857,14 @@ private function createPoolCacheDefinition(ContainerBuilder $container, string $
return $serviceId;
}

private function getPoolNameForCacheDriver(string $driverName) : string
private function createArrayAdapterCachePool(ContainerBuilder $container, string $objectManagerName, string $cacheName) : string
{
switch ($driverName) {
case 'metadata_cache':
return 'cache.system';
default:
return 'cache.app';
}
$id = sprintf('cache.doctrine.orm.%s.%s', $objectManagerName, str_replace('_cache', '', $cacheName));

$poolDefinition = $container->register($id, ArrayAdapter::class);
$poolDefinition->addTag('cache.pool');
$container->setDefinition($id, $poolDefinition);

return $id;
}
}
4 changes: 2 additions & 2 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Expand Up @@ -348,13 +348,13 @@ public function testLoadMultipleConnections()
$this->assertEquals(DoctrineProvider::class, $definition->getClass());
$arguments = $definition->getArguments();
$this->assertInstanceOf(Reference::class, $arguments[0]);
$this->assertEquals('cache.app', (string) $arguments[0]);
$this->assertEquals('cache.doctrine.orm.em1.query', (string) $arguments[0]);

$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_result_cache'));
$this->assertEquals(DoctrineProvider::class, $definition->getClass());
$arguments = $definition->getArguments();
$this->assertInstanceOf(Reference::class, $arguments[0]);
$this->assertEquals('cache.app', (string) $arguments[0]);
$this->assertEquals('cache.doctrine.orm.em1.result', (string) $arguments[0]);
}

public function testLoadLogging()
Expand Down
21 changes: 12 additions & 9 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Expand Up @@ -323,19 +323,22 @@ public function testDependencyInjectionConfigurationDefaults()
$this->assertEquals(DoctrineProvider::class, $definition->getClass());
$arguments = $definition->getArguments();
$this->assertInstanceOf(Reference::class, $arguments[0]);
$this->assertEquals('cache.system', (string) $arguments[0]);
$this->assertEquals('cache.doctrine.orm.default.metadata', (string) $arguments[0]);
$this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass());

$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_query_cache'));
$this->assertEquals(DoctrineProvider::class, $definition->getClass());
$arguments = $definition->getArguments();
$this->assertInstanceOf(Reference::class, $arguments[0]);
$this->assertEquals('cache.app', (string) $arguments[0]);
$this->assertEquals('cache.doctrine.orm.default.query', (string) $arguments[0]);
$this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass());

$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_result_cache'));
$this->assertEquals(DoctrineProvider::class, $definition->getClass());
$arguments = $definition->getArguments();
$this->assertInstanceOf(Reference::class, $arguments[0]);
$this->assertEquals('cache.app', (string) $arguments[0]);
$this->assertEquals('cache.doctrine.orm.default.result', (string) $arguments[0]);
$this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass());
}

public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection()
Expand Down Expand Up @@ -722,38 +725,38 @@ public static function cacheConfigurationProvider() : array
return [
'metadata_cache_default' => [
'expectedAliasName' => 'doctrine.orm.default_metadata_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.pool.cache.system',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.metadata',
'cacheName' => 'metadata_cache_driver',
'cacheConfig' => ['type' => null],
],
'query_cache_default' => [
'expectedAliasName' => 'doctrine.orm.default_query_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.pool.cache.app',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.query',
'cacheName' => 'query_cache_driver',
'cacheConfig' => ['type' => null],
],
'result_cache_default' => [
'expectedAliasName' => 'doctrine.orm.default_result_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.pool.cache.app',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.result',
'cacheName' => 'result_cache_driver',
'cacheConfig' => ['type' => null],
],

'metadata_cache_pool' => [
'expectedAliasName' => 'doctrine.orm.default_metadata_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.pool.metadata_cache_pool',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.metadata_cache_pool',
'cacheName' => 'metadata_cache_driver',
'cacheConfig' => ['type' => 'pool', 'pool' => 'metadata_cache_pool'],
],
'query_cache_pool' => [
'expectedAliasName' => 'doctrine.orm.default_query_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.pool.query_cache_pool',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.query_cache_pool',
'cacheName' => 'query_cache_driver',
'cacheConfig' => ['type' => 'pool', 'pool' => 'query_cache_pool'],
],
'result_cache_pool' => [
'expectedAliasName' => 'doctrine.orm.default_result_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.pool.result_cache_pool',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.result_cache_pool',
'cacheName' => 'result_cache_driver',
'cacheConfig' => ['type' => 'pool', 'pool' => 'result_cache_pool'],
],
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -28,6 +28,7 @@
"php": "^7.1",
"doctrine/dbal": "^2.9.0",
"jdorn/sql-formatter": "^1.2.16",
"symfony/cache": "^4.3.3|^5.0",
"symfony/config": "^4.3.3|^5.0",
"symfony/console": "^3.4.30|^4.3.3|^5.0",
"symfony/dependency-injection": "^4.3.3|^5.0",
Expand All @@ -38,7 +39,6 @@
"doctrine/coding-standard": "^6.0",
"doctrine/orm": "^2.6",
"phpunit/phpunit": "^7.5",
"symfony/cache": "^3.4.30|^4.3.3|^5.0",
"symfony/phpunit-bridge": "^4.2",
"symfony/property-info": "^4.3.3|^5.0",
"symfony/twig-bridge": "^3.4.30|^4.3.3|^5.0",
Expand Down

0 comments on commit 6e2923b

Please sign in to comment.