From 4decb9352208847e45254b14bac01d3622f2a37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Wed, 2 Jun 2021 23:35:09 +0200 Subject: [PATCH] Revert "Disallow mixed use of simplified and non-simplified configuration" This reverts problematic parts of commit 759018e8 We will go with something else instead. Most likely deprecating it in some form and trigger error later. --- DependencyInjection/Configuration.php | 39 ++++++------------- .../AbstractDoctrineExtensionTest.php | 12 ------ UPGRADE-2.4.md | 30 -------------- 3 files changed, 11 insertions(+), 70 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4fa5f2971..1a1a60f85 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -3,7 +3,6 @@ namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection; use Doctrine\ORM\EntityManager; -use InvalidArgumentException; use ReflectionClass; use Symfony\Component\Config\Definition\BaseNode; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; @@ -13,6 +12,7 @@ use Symfony\Component\DependencyInjection\Exception\LogicException; use function array_intersect_key; +use function array_key_exists; use function array_keys; use function array_pop; use function assert; @@ -72,15 +72,10 @@ private function addDbalSection(ArrayNodeDefinition $node): void ->children() ->arrayNode('dbal') ->beforeNormalization() - ->always(static function (array $v): array { - static $hasExplicitlyDefinedConnectionsAtLeastOnce = false; - - if (isset($v['connections']) || isset($v['connection'])) { - $hasExplicitlyDefinedConnectionsAtLeastOnce = true; - - return $v; - } - + ->ifTrue(static function ($v) { + return is_array($v) && ! array_key_exists('connections', $v) && ! array_key_exists('connection', $v); + }) + ->then(static function ($v) { // Key that should not be rewritten to the connection config $excludedKeys = ['default_connection' => true, 'types' => true, 'type' => true]; $connection = []; @@ -93,10 +88,6 @@ private function addDbalSection(ArrayNodeDefinition $node): void unset($v[$key]); } - if ($connection && $hasExplicitlyDefinedConnectionsAtLeastOnce) { - throw new InvalidArgumentException('Seems like you have configured multiple "dbal" connections. You need to use the long configuration syntax in every doctrine configuration file, or in none of them.'); - } - $v['default_connection'] = isset($v['default_connection']) ? (string) $v['default_connection'] : 'default'; $v['connections'] = [$v['default_connection'] => $connection]; @@ -380,19 +371,15 @@ private function addOrmSection(ArrayNodeDefinition $node): void ->children() ->arrayNode('orm') ->beforeNormalization() - ->always(static function (array $v): array { - if ($v && ! class_exists(EntityManager::class)) { + ->ifTrue(static function ($v) { + if (! empty($v) && ! class_exists(EntityManager::class)) { throw new LogicException('The doctrine/orm package is required when the doctrine.orm config is set.'); } - static $hasExplicitlyDefinedEntityManagersAtLeastOnce = false; - - if (isset($v['entity_managers']) || isset($v['entity_manager'])) { - $hasExplicitlyDefinedEntityManagersAtLeastOnce = true; - - return $v; - } - + return $v === null || (is_array($v) && ! array_key_exists('entity_managers', $v) && ! array_key_exists('entity_manager', $v)); + }) + ->then(static function ($v) { + $v = (array) $v; // Key that should not be rewritten to the connection config $excludedKeys = [ 'default_entity_manager' => true, @@ -412,10 +399,6 @@ private function addOrmSection(ArrayNodeDefinition $node): void unset($v[$key]); } - if ($entityManager && $hasExplicitlyDefinedEntityManagersAtLeastOnce) { - throw new InvalidArgumentException('Seems like you have configured multiple "entity_managers". You need to use the long configuration syntax in every doctrine configuration file, or in none of them.'); - } - $v['default_entity_manager'] = isset($v['default_entity_manager']) ? (string) $v['default_entity_manager'] : 'default'; $v['entity_managers'] = [$v['default_entity_manager'] => $entityManager]; diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 83f021a01..a6634341d 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -216,18 +216,6 @@ class_exists(PrimaryReadReplicaConnection::class) ? $this->assertEquals(['engine' => 'InnoDB'], $param['defaultTableOptions']); } - public function testMixedUseOfSimplifiedAndMultipleConnectionsStyleIsInvalid(): void - { - $this->expectExceptionObject(new InvalidArgumentException('Seems like you have configured multiple "dbal" connections. You need to use the long configuration syntax in every doctrine configuration file, or in none of them.')); - $this->loadContainer('dbal_service_{single,multiple}_connectio{n,ns}'); - } - - public function testMixedUseOfSimplifiedAndMultipleEntityManagersStyleIsInvalid(): void - { - $this->expectExceptionObject(new InvalidArgumentException('Seems like you have configured multiple "entity_managers". You need to use the long configuration syntax in every doctrine configuration file, or in none of them.')); - $this->loadContainer('orm_service_{simple_single,multiple}_entity_manage{r,rs}'); - } - public function testDbalLoadPoolShardingConnection(): void { $container = $this->loadContainer('dbal_service_pool_sharding_connection'); diff --git a/UPGRADE-2.4.md b/UPGRADE-2.4.md index a143c259a..a6686db39 100644 --- a/UPGRADE-2.4.md +++ b/UPGRADE-2.4.md @@ -7,36 +7,6 @@ Configuration * Setting the `host`, `port`, `user`, `password`, `path`, `dbname`, `unix_socket` or `memory` configuration options while the `url` one is set has been deprecated. * The `override_url` configuration option has been deprecated. - * Combined use of simplified connection configuration in DBAL (without `connections` key) - and multiple connection configuration is disallowed now. If you experience this issue, instead of -```yaml -doctrine: - dbal: - url: '%env(DATABASE_URL)%' -``` -use -```yaml -doctrine: - dbal: - connections: - default: - url: '%env(DATABASE_URL)%' -``` -* Combined use of simplified entity manager configuration in ORM (without `entity_managers` key) - and multiple entity managers configuration is disallowed now. If you experience this issue, instead of -```yaml -doctrine: - orm: - mappings: -``` -use -```yaml -doctrine: - orm: - entity_managers: - default: - mappings: -``` ConnectionFactory --------