bug #32380 [Messenger] fix broken key normalization (Tobion)

This PR was merged into the 4.3 branch.

Discussion
----------

[Messenger] fix broken key normalization

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

Disable broken key normalization in messenger config.

If you tried to use `-` in a transport/bus it didn't work and you get a cryptic error (#31613)

```
framework:
    messenger:
        transports:
            my-bus: '...'
        routing:
            Acme\MyMessage: my-bus
```

The default behavior of normalizing keys is really annoying and a waste of time in most cases. I've measured `\Symfony\Component\Config\Definition\ArrayNode::preNormalize` in a project and it takes 4 ms.
As an idea, we could disabling normalizing keys automatically when you call `useAttributeAsKey` because the value is then user-provided and shouldn't be modified (in contrast to children properties of an arrayNode which should get normalized for xml support).

Commits
-------

9931b3e183 [Messenger] fix broken key normalization
This commit is contained in:
Fabien Potencier 2019-07-05 06:27:58 +02:00
commit c799fc803d

View File

@ -1114,6 +1114,7 @@ class Configuration implements ConfigurationInterface
->end()
->children()
->arrayNode('routing')
->normalizeKeys(false)
->useAttributeAsKey('message_class')
->beforeNormalization()
->always()
@ -1173,6 +1174,7 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->arrayNode('transports')
->normalizeKeys(false)
->useAttributeAsKey('name')
->arrayPrototype()
->beforeNormalization()
@ -1220,6 +1222,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('default_bus')->defaultNull()->end()
->arrayNode('buses')
->defaultValue(['messenger.bus.default' => ['default_middleware' => true, 'middleware' => []]])
->normalizeKeys(false)
->useAttributeAsKey('name')
->arrayPrototype()
->addDefaultsIfNotSet()