vendor/jms/serializer-bundle/JMSSerializerBundle.php line 18

Open in your IDE?
  1. <?php
  2. namespace JMS\SerializerBundle;
  3. use JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass;
  4. use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersLocatorPass;
  5. use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass;
  6. use JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass;
  7. use JMS\SerializerBundle\DependencyInjection\Compiler\ExpressionFunctionProviderPass;
  8. use JMS\SerializerBundle\DependencyInjection\Compiler\FormErrorHandlerTranslationDomainPass;
  9. use JMS\SerializerBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass;
  10. use JMS\SerializerBundle\DependencyInjection\Compiler\ServiceMapPass;
  11. use JMS\SerializerBundle\DependencyInjection\Compiler\TwigExtensionPass;
  12. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\HttpKernel\Bundle\Bundle;
  15. class JMSSerializerBundle extends Bundle
  16. {
  17. public function build(ContainerBuilder $builder)
  18. {
  19. $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.serialization_visitor', 'format',
  20. function (ContainerBuilder $container, $def) {
  21. $container->getDefinition('jms_serializer.serializer')->replaceArgument(2, $def);
  22. }
  23. ));
  24. $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.deserialization_visitor', 'format',
  25. function (ContainerBuilder $container, $def) {
  26. $container->getDefinition('jms_serializer.serializer')->replaceArgument(3, $def);
  27. }
  28. ));
  29. // Should run before Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass
  30. $builder->addCompilerPass(new TwigExtensionPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10);
  31. $builder->addCompilerPass(new FormErrorHandlerTranslationDomainPass());
  32. $builder->addCompilerPass(new ExpressionFunctionProviderPass());
  33. $builder->addCompilerPass(new DoctrinePass());
  34. $builder->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_OPTIMIZE);
  35. $builder->addCompilerPass(new CustomHandlersPass(), PassConfig::TYPE_OPTIMIZE);
  36. }
  37. private function getServiceMapPass($tagName, $keyAttributeName, $callable)
  38. {
  39. if (class_exists('JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass')) {
  40. return new LazyServiceMapPass($tagName, $keyAttributeName, $callable);
  41. }
  42. return new ServiceMapPass($tagName, $keyAttributeName, $callable);
  43. }
  44. }