From a05e2e2c3b996cfead88c0fb6677684e5174e44f Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Fri, 27 Apr 2018 23:07:51 -0400 Subject: [PATCH] Relax Messenger config and fix some bugs --- .../DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/FrameworkExtension.php | 11 +++++++++-- .../DependencyInjection/ConfigurationTest.php | 2 +- .../Fixtures/php/messenger.php | 1 + .../messenger_amqp_transport_no_serializer.php | 12 ++++++++++++ .../Fixtures/php/messenger_transport.php | 1 + .../Fixtures/php/messenger_transports.php | 1 + .../Fixtures/php/serializer_disabled.php | 3 +++ .../Fixtures/xml/messenger.xml | 1 + .../messenger_amqp_transport_no_serializer.xml | 14 ++++++++++++++ .../Fixtures/xml/messenger_transport.xml | 1 + .../Fixtures/xml/messenger_transports.xml | 1 + .../Fixtures/xml/serializer_disabled.xml | 3 +++ .../Fixtures/yml/messenger.yml | 1 + .../messenger_amqp_transport_no_serializer.yml | 5 +++++ .../Fixtures/yml/messenger_transport.yml | 1 + .../Fixtures/yml/messenger_transports.yml | 1 + .../Fixtures/yml/serializer_disabled.yml | 2 ++ .../FrameworkExtensionTest.php | 16 ++++++++++++++-- 19 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_amqp_transport_no_serializer.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_amqp_transport_no_serializer.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_amqp_transport_no_serializer.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index c0ab2cc766d4d..f46397e57cd46 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1010,7 +1010,7 @@ function ($a) { ->end() ->end() ->arrayNode('serializer') - ->canBeDisabled() + ->{!class_exists(FullStack::class) && class_exists(Serializer::class) ? 'canBeDisabled' : 'canBeEnabled'}() ->addDefaultsIfNotSet() ->children() ->scalarNode('format')->defaultValue('json')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 806d8d729b940..b1a1e8eb5d961 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1449,8 +1449,8 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder $loader->load('messenger.xml'); if ($this->isConfigEnabled($container, $config['serializer'])) { - if (\count($config['transports']) > 0 && !$this->isConfigEnabled($container, $serializerConfig)) { - throw new LogicException('Using the default encoder/decoder, Symfony Messenger requires the Serializer. Enable it or install it by running "composer require symfony/serializer-pack".'); + if (!$this->isConfigEnabled($container, $serializerConfig)) { + throw new LogicException('The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enable it or install it by running "composer require symfony/serializer-pack".'); } $container->getDefinition('messenger.transport.serializer') @@ -1458,6 +1458,9 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder ->replaceArgument(2, $config['serializer']['context']); } else { $container->removeDefinition('messenger.transport.serializer'); + if ('messenger.transport.serializer' === $config['encoder'] || 'messenger.transport.serializer' === $config['decoder']) { + $container->removeDefinition('messenger.transport.amqp.factory'); + } } $container->setAlias('messenger.transport.encoder', $config['encoder']); @@ -1506,6 +1509,10 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder $container->getDefinition('messenger.asynchronous.routing.sender_locator')->replaceArgument(1, $messageToSenderIdsMapping); foreach ($config['transports'] as $name => $transport) { + if (0 === strpos($transport['dsn'], 'amqp://') && !$container->hasDefinition('messenger.transport.amqp.factory')) { + throw new LogicException('The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enable it or install it by running "composer require symfony/serializer-pack".'); + } + $senderDefinition = (new Definition(SenderInterface::class)) ->setFactory(array(new Reference('messenger.transport_factory'), 'createSender')) ->setArguments(array($transport['dsn'], $transport['options'])) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 931edb590895f..e93c67f448ace 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -256,7 +256,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor 'routing' => array(), 'transports' => array(), 'serializer' => array( - 'enabled' => true, + 'enabled' => !class_exists(FullStack::class), 'format' => 'json', 'context' => array(), ), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger.php index 16b311f5cd985..0135ee69e0e3d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger.php @@ -5,6 +5,7 @@ $container->loadFromExtension('framework', array( 'messenger' => array( + 'serializer' => false, 'routing' => array( FooMessage::class => array('sender.bar', 'sender.biz'), BarMessage::class => 'sender.foo', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_amqp_transport_no_serializer.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_amqp_transport_no_serializer.php new file mode 100644 index 0000000000000..f2389d5426eae --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_amqp_transport_no_serializer.php @@ -0,0 +1,12 @@ +loadFromExtension('framework', array( + 'messenger' => array( + 'serializer' => array( + 'enabled' => false, + ), + 'transports' => array( + 'default' => 'amqp://localhost/%2f/messages', + ), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transport.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transport.php index ec90a3197b1ef..60c4800e3f2f0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transport.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transport.php @@ -1,6 +1,7 @@ loadFromExtension('framework', array( + 'serializer' => true, 'messenger' => array( 'serializer' => array( 'format' => 'csv', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transports.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transports.php index 3f90bda7f3777..1f802867185d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transports.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transports.php @@ -3,6 +3,7 @@ $container->loadFromExtension('framework', array( 'serializer' => true, 'messenger' => array( + 'serializer' => true, 'transports' => array( 'default' => 'amqp://localhost/%2f/messages', 'customised' => array( diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_disabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_disabled.php index dedd090beb774..7f96c4e44e69f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_disabled.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_disabled.php @@ -4,4 +4,7 @@ 'serializer' => array( 'enabled' => false, ), + 'messenger' => array( + 'serializer' => false, + ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger.xml index 0a130ce0bac3d..37c58b6a9dd06 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger.xml @@ -7,6 +7,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_amqp_transport_no_serializer.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_amqp_transport_no_serializer.xml new file mode 100644 index 0000000000000..0863ef6820000 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_amqp_transport_no_serializer.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transport.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transport.xml index ca7c597d44aae..bcca131a53e50 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transport.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transport.xml @@ -6,6 +6,7 @@ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transports.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transports.xml index 211135570c232..b3f9505de1f20 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transports.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transports.xml @@ -8,6 +8,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_disabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_disabled.xml index 73f1dccb1a6ed..4ffd1351742b3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_disabled.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_disabled.xml @@ -7,5 +7,8 @@ + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger.yml index 7f038af11fdff..0983f2ef321ee 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger.yml @@ -1,5 +1,6 @@ framework: messenger: + serializer: false routing: 'Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage': ['sender.bar', 'sender.biz'] 'Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage': 'sender.foo' diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_amqp_transport_no_serializer.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_amqp_transport_no_serializer.yml new file mode 100644 index 0000000000000..e31f3275a479b --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_amqp_transport_no_serializer.yml @@ -0,0 +1,5 @@ +framework: + messenger: + serializer: false + transports: + default: 'amqp://localhost/%2f/messages' diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transport.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transport.yml index af590a5169973..7abed80e5df45 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transport.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transport.yml @@ -1,4 +1,5 @@ framework: + serializer: true messenger: serializer: format: csv diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transports.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transports.yml index 0c38638679598..4522212f4d320 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transports.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transports.yml @@ -1,6 +1,7 @@ framework: serializer: true messenger: + serializer: true transports: default: 'amqp://localhost/%2f/messages' customised: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_disabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_disabled.yml index 330e19a6976e7..e629f4aea4e25 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_disabled.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_disabled.yml @@ -1,3 +1,5 @@ framework: serializer: enabled: false + messenger: + serializer: false diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 49a87b5869c75..f6cf5637f511b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -526,7 +526,8 @@ public function testWebLink() public function testMessenger() { $container = $this->createContainerFromFile('messenger'); - $this->assertTrue($container->has('message_bus')); + $this->assertTrue($container->hasAlias('message_bus')); + $this->assertFalse($container->hasDefinition('messenger.transport.amqp.factory')); } public function testMessengerTransports() @@ -556,6 +557,8 @@ public function testMessengerTransports() $this->assertCount(2, $receiverArguments); $this->assertSame('amqp://localhost/%2f/messages?exchange_name=exchange_name', $receiverArguments[0]); $this->assertSame(array('queue' => array('name' => 'Queue')), $receiverArguments[1]); + + $this->assertTrue($container->hasDefinition('messenger.transport.amqp.factory')); } public function testMessengerRouting() @@ -574,13 +577,22 @@ public function testMessengerRouting() /** * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException - * @expectedExceptionMessage Using the default encoder/decoder, Symfony Messenger requires the Serializer. Enable it or install it by running "composer require symfony/serializer-pack". + * @expectedExceptionMessage The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enable it or install it by running "composer require symfony/serializer-pack". */ public function testMessengerTransportConfigurationWithoutSerializer() { $this->createContainerFromFile('messenger_transport_no_serializer'); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException + * @expectedExceptionMessage The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enable it or install it by running "composer require symfony/serializer-pack". + */ + public function testMessengerAMQPTransportConfigurationWithoutSerializer() + { + $this->createContainerFromFile('messenger_amqp_transport_no_serializer'); + } + public function testMessengerTransportConfiguration() { $container = $this->createContainerFromFile('messenger_transport'); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy