diff --git a/DependencyInjection/Compiler/CustomHandlersPass.php b/DependencyInjection/Compiler/CustomHandlersPass.php index 7e042931..39e7de5c 100644 --- a/DependencyInjection/Compiler/CustomHandlersPass.php +++ b/DependencyInjection/Compiler/CustomHandlersPass.php @@ -6,6 +6,7 @@ use JMS\Serializer\GraphNavigatorInterface; use JMS\Serializer\Handler\HandlerRegistry; +use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -26,7 +27,7 @@ public function process(ContainerBuilder $container) foreach ($handlersByFormat as $format => $handlerCallable) { $id = (string) $handlerCallable[0]; - $handlerServices[$id] = $handlerCallable[0]; + $handlerServices[$id] = new ServiceClosureArgument($handlerCallable[0]); $handlerCallable[0] = $id; $handlerRegistryDef->addMethodCall('registerHandler', [$direction, $type, $format, $handlerCallable]); diff --git a/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php b/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php index 75ac1d84..cd6f0cc3 100644 --- a/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php +++ b/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php @@ -5,6 +5,7 @@ namespace JMS\SerializerBundle\DependencyInjection\Compiler; use JMS\Serializer\EventDispatcher\EventDispatcher; +use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -29,7 +30,7 @@ public function process(ContainerBuilder $container) foreach ($listenersPerEvent as $singleListener) { $id = (string) $singleListener[0][0]; - $listenerServices[$id] = $singleListener[0][0]; + $listenerServices[$id] = new ServiceClosureArgument($singleListener[0][0]); $singleListener[0][0] = $id; $dispatcherDef->addMethodCall('addListener', array_merge([$event], $singleListener)); diff --git a/JMSSerializerBundle.php b/JMSSerializerBundle.php index 9d931ee0..a2ce0321 100644 --- a/JMSSerializerBundle.php +++ b/JMSSerializerBundle.php @@ -35,8 +35,8 @@ function (ContainerBuilder $container, $def) { $builder->addCompilerPass(new ExpressionFunctionProviderPass()); $builder->addCompilerPass(new DoctrinePass()); - $builder->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -256); - $builder->addCompilerPass(new CustomHandlersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -256); + $builder->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_OPTIMIZE); + $builder->addCompilerPass(new CustomHandlersPass(), PassConfig::TYPE_OPTIMIZE); } private function getServiceMapPass($tagName, $keyAttributeName, $callable)