From aa383604c6717c24bb9d787f3132edc4c2df1594 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 23:25:57 +0200 Subject: [PATCH] do not decorate the jms handler registry for jms v4 --- .../HandlerRegistryDecorationPass.php | 1 + .../JMSHandlerRegistryV4DecorationPass.php | 49 ------------------- FOSRestBundle.php | 2 - Tests/Functional/DependencyInjectionTest.php | 5 ++ 4 files changed, 6 insertions(+), 51 deletions(-) delete mode 100644 DependencyInjection/Compiler/JMSHandlerRegistryV4DecorationPass.php diff --git a/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php b/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php index 6375b83e3..a2ca348fd 100644 --- a/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php +++ b/DependencyInjection/Compiler/HandlerRegistryDecorationPass.php @@ -33,6 +33,7 @@ class HandlerRegistryDecorationPass implements CompilerPassInterface { public function process(ContainerBuilder $container): void { + // skip if JMSSerializerBundle is not installed or if JMSSerializerBundle >= 4.0 if (!$container->has('fos_rest.serializer.jms_handler_registry') || $container->has('jms_serializer.handler_registry.service_locator')) { return; } diff --git a/DependencyInjection/Compiler/JMSHandlerRegistryV4DecorationPass.php b/DependencyInjection/Compiler/JMSHandlerRegistryV4DecorationPass.php deleted file mode 100644 index 70a3bdaa6..000000000 --- a/DependencyInjection/Compiler/JMSHandlerRegistryV4DecorationPass.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\RestBundle\DependencyInjection\Compiler; - -use FOS\RestBundle\Serializer\JMSHandlerRegistryV2; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Reference; - -/** - * Decorates the handler registry from JMSSerializerBundle. - * - * It works as HandlerRegistryDecorationPass but uses the symfony built-in decoration mechanism. - * This way of decoration is possible only starting from jms/serializer-bundle:4.0 . - * - * @author Asmir Mustafic - * - * @internal - */ -class JMSHandlerRegistryV4DecorationPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container): void - { - // skip if jms/serializer-bundle is not installed or < 4.0 - if (!$container->has('jms_serializer.handler_registry') || !$container->has('jms_serializer.handler_registry.service_locator')) { - return; - } - - $fosRestHandlerRegistry = new Definition( - JMSHandlerRegistryV2::class, - [ - new Reference('fos_rest.serializer.jms_handler_registry.inner'), - ] - ); - - $fosRestHandlerRegistry->setDecoratedService('jms_serializer.handler_registry'); - $container->setDefinition('fos_rest.serializer.jms_handler_registry', $fosRestHandlerRegistry); - } -} diff --git a/FOSRestBundle.php b/FOSRestBundle.php index 5583998e0..5166a71ea 100644 --- a/FOSRestBundle.php +++ b/FOSRestBundle.php @@ -14,7 +14,6 @@ use FOS\RestBundle\DependencyInjection\Compiler\ConfigurationCheckPass; use FOS\RestBundle\DependencyInjection\Compiler\HandlerRegistryDecorationPass; use FOS\RestBundle\DependencyInjection\Compiler\JMSFormErrorHandlerPass; -use FOS\RestBundle\DependencyInjection\Compiler\JMSHandlerRegistryV4DecorationPass; use FOS\RestBundle\DependencyInjection\Compiler\JMSHandlersPass; use FOS\RestBundle\DependencyInjection\Compiler\FormatListenerRulesPass; use FOS\RestBundle\DependencyInjection\Compiler\SerializerConfigurationPass; @@ -40,7 +39,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new FormatListenerRulesPass()); $container->addCompilerPass(new JMSFormErrorHandlerPass()); $container->addCompilerPass(new JMSHandlersPass(), PassConfig::TYPE_BEFORE_REMOVING, -10); - $container->addCompilerPass(new JMSHandlerRegistryV4DecorationPass()); $container->addCompilerPass(new HandlerRegistryDecorationPass(), PassConfig::TYPE_AFTER_REMOVING); } } diff --git a/Tests/Functional/DependencyInjectionTest.php b/Tests/Functional/DependencyInjectionTest.php index f84bbb094..a7b435852 100644 --- a/Tests/Functional/DependencyInjectionTest.php +++ b/Tests/Functional/DependencyInjectionTest.php @@ -16,6 +16,7 @@ use FOS\RestBundle\Serializer\JMSHandlerRegistryV2; use FOS\RestBundle\Serializer\Normalizer\FormErrorHandler; use JMS\Serializer\Visitor\SerializationVisitorInterface; +use JMS\SerializerBundle\Debug\TraceableHandlerRegistry; use JMS\SerializerBundle\JMSSerializerBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -33,6 +34,10 @@ public function testSerializerRelatedServicesAreNotRemovedWhenJmsSerializerBundl $this->assertInstanceOf(FormErrorHandler::class, $container->get('test.jms_serializer.form_error_handler')); + if (class_exists(TraceableHandlerRegistry::class)) { + $this->markTestIncomplete('Starting from jms/serializer-bundle 4.0 the handler registry is not decorated anymore'); + } + $this->assertInstanceOf( interface_exists(SerializationVisitorInterface::class) ? JMSHandlerRegistryV2::class : JMSHandlerRegistry::class, $container->get('test.jms_serializer.handler_registry')