Skip to content

Commit

Permalink
Revert "Disallow mixed use of simplified and non-simplified configura…
Browse files Browse the repository at this point in the history
…tion"

This reverts problematic parts of commit 759018e

We will go with something else instead. Most likely deprecating it in some form and trigger error later.
  • Loading branch information
ostrolucky committed Jun 3, 2021
1 parent 3242af8 commit 4decb93
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 70 deletions.
39 changes: 11 additions & 28 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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];

Expand Down Expand Up @@ -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,
Expand All @@ -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];

Expand Down
12 changes: 0 additions & 12 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
30 changes: 0 additions & 30 deletions UPGRADE-2.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down

0 comments on commit 4decb93

Please sign in to comment.