Skip to content

Commit

Permalink
move registration to optimization step
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Aug 7, 2021
1 parent be3952a commit b24aa10
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion DependencyInjection/Compiler/CustomHandlersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions JMSSerializerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b24aa10

Please sign in to comment.