Skip to content

Commit

Permalink
symfony#39102: register the SerializerDebugPass and configured decora…
Browse files Browse the repository at this point in the history
…tor and data_collector for the container.
  • Loading branch information
Basster committed Mar 6, 2021
1 parent b896d64 commit 7368cfb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Serializer\Debug\Normalizer\TraceableDenormalizer;
use Symfony\Component\Serializer\Debug\Normalizer\TraceableHybridNormalizer;
use Symfony\Component\Serializer\Debug\Normalizer\TraceableNormalizer;
use Symfony\Component\Serializer\Debug\TraceableSerializer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

Expand All @@ -30,6 +31,10 @@ class SerializerDebugPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('serializer')) {
return;
}

foreach ($container->findTaggedServiceIds('serializer.normalizer') as $id => $tags) {
$this->decorateNormalizer($id, $container);
}
Expand Down Expand Up @@ -64,7 +69,7 @@ private function decorateNormalizer(string $id, ContainerBuilder $container): vo
} elseif ($isDenormalizer) {
$decoratorClass = TraceableDenormalizer::class;
} else {
throw new RuntimeException(sprintf('Normalizer with id %s neither implements NormalizerInterface nor DenormalizerInterface!', $id));
throw new RuntimeException(sprintf('Normalizer with id "%s" neither implements NormalizerInterface nor DenormalizerInterface!', $id));
}

$decoratorDef = (new Definition($decoratorClass))
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Expand Up @@ -20,6 +20,7 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerDebugPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SessionPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
Expand Down Expand Up @@ -166,6 +167,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
$container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new SerializerDebugPass());
}
}

Expand Down
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Serializer\DataCollector\SerializerDataCollector;
use Symfony\Component\Serializer\Debug\TraceableSerializer;

return static function (ContainerConfigurator $container) {
$container->services()
->set('debug.serializer', TraceableSerializer::class)
->decorate('serializer', null, 255)
->args([
service('debug.serializer.inner'),
])
->tag('kernel.reset', [
'method' => 'reset',
])

->set('data_collector.serializer', SerializerDataCollector::class)
->args([
service('debug.serializer'),
tagged_iterator('debug.normalizer')
])
->tag('data_collector', [
'template' => '@WebProfiler/Collector/serializer.html.twig',
'id' => 'serializer',
])
;
};
Expand Up @@ -51,7 +51,7 @@ public function collect(Request $request, Response $response, Throwable $excepti

public function getName(): string
{
return 'serializer.data_collector';
return 'serializer';
}

public function reset(): void
Expand Down

0 comments on commit 7368cfb

Please sign in to comment.