Skip to content

Instantly share code, notes, and snippets.

@vudaltsov
Last active July 19, 2020 19:56
Show Gist options
  • Save vudaltsov/35fdfdf8785d5cb870c8b2d3644e1b6e to your computer and use it in GitHub Desktop.
Save vudaltsov/35fdfdf8785d5cb870c8b2d3644e1b6e to your computer and use it in GitHub Desktop.
Removing unnecessary Symfony services via a compiler pass
<?php
declare(strict_types=1);
namespace Application;
use Application\DependencyInjection\RemoveObjectNormalizerPass;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
final class AppKernel extends Kernel
{
// ...
/**
* {@inheritDoc}
*/
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
// ...
$container->addCompilerPass(new RemoveObjectNormalizerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 200);
}
}
<?php
declare(strict_types=1);
namespace Application\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
final class RemoveObjectNormalizerPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container): void
{
$container->removeDefinition('serializer.normalizer.object');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment