vendor/symfony/framework-bundle/FrameworkBundle.php line 66

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle;
  11. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
  13. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
  14. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
  15. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
  16. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
  17. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
  18. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
  19. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
  20. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
  21. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
  22. use Symfony\Component\Cache\DependencyInjection\CacheCollectorPass;
  23. use Symfony\Component\Cache\DependencyInjection\CachePoolClearerPass;
  24. use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
  25. use Symfony\Component\Cache\DependencyInjection\CachePoolPrunerPass;
  26. use Symfony\Component\Config\Resource\ClassExistenceResource;
  27. use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
  28. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  29. use Symfony\Component\DependencyInjection\Compiler\RegisterReverseContainerPass;
  30. use Symfony\Component\DependencyInjection\ContainerBuilder;
  31. use Symfony\Component\ErrorHandler\ErrorHandler;
  32. use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
  33. use Symfony\Component\Form\DependencyInjection\FormPass;
  34. use Symfony\Component\HttpClient\DependencyInjection\HttpClientPass;
  35. use Symfony\Component\HttpFoundation\Request;
  36. use Symfony\Component\HttpKernel\Bundle\Bundle;
  37. use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
  38. use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
  39. use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
  40. use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
  41. use Symfony\Component\HttpKernel\DependencyInjection\RegisterLocaleAwareServicesPass;
  42. use Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass;
  43. use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
  44. use Symfony\Component\HttpKernel\KernelEvents;
  45. use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
  46. use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
  47. use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
  48. use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
  49. use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
  50. use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass;
  51. use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
  52. use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
  53. use Symfony\Component\Translation\DependencyInjection\TranslatorPathsPass;
  54. use Symfony\Component\Validator\DependencyInjection\AddAutoMappingConfigurationPass;
  55. use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
  56. use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
  57. /**
  58.  * Bundle.
  59.  *
  60.  * @author Fabien Potencier <fabien@symfony.com>
  61.  */
  62. class FrameworkBundle extends Bundle
  63. {
  64.     public function boot()
  65.     {
  66.         ErrorHandler::register(nullfalse)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
  67.         if ($this->container->getParameter('kernel.http_method_override')) {
  68.             Request::enableHttpMethodParameterOverride();
  69.         }
  70.         if ($trustedHosts $this->container->getParameter('kernel.trusted_hosts')) {
  71.             Request::setTrustedHosts($trustedHosts);
  72.         }
  73.     }
  74.     public function build(ContainerBuilder $container)
  75.     {
  76.         parent::build($container);
  77.         $hotPathEvents = [
  78.             KernelEvents::REQUEST,
  79.             KernelEvents::CONTROLLER,
  80.             KernelEvents::CONTROLLER_ARGUMENTS,
  81.             KernelEvents::RESPONSE,
  82.             KernelEvents::FINISH_REQUEST,
  83.         ];
  84.         $container->addCompilerPass(new LoggerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
  85.         $container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
  86.         $container->addCompilerPass(new RemoveEmptyControllerArgumentLocatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
  87.         $container->addCompilerPass(new RoutingResolverPass());
  88.         $container->addCompilerPass(new ProfilerPass());
  89.         // must be registered before removing private services as some might be listeners/subscribers
  90.         // but as late as possible to get resolved parameters
  91.         $container->addCompilerPass((new RegisterListenersPass())->setHotPathEvents($hotPathEvents), PassConfig::TYPE_BEFORE_REMOVING);
  92.         $this->addCompilerPassIfExists($containerAddConstraintValidatorsPass::class);
  93.         $container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_AFTER_REMOVING, -255);
  94.         $this->addCompilerPassIfExists($containerAddValidatorInitializersPass::class);
  95.         $this->addCompilerPassIfExists($containerAddConsoleCommandPass::class, PassConfig::TYPE_BEFORE_REMOVING);
  96.         // must be registered as late as possible to get access to all Twig paths registered in
  97.         // twig.template_iterator definition
  98.         $this->addCompilerPassIfExists($containerTranslatorPass::class, PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
  99.         $this->addCompilerPassIfExists($containerTranslatorPathsPass::class, PassConfig::TYPE_AFTER_REMOVING);
  100.         $container->addCompilerPass(new LoggingTranslatorPass());
  101.         $container->addCompilerPass(new AddExpressionLanguageProvidersPass(false));
  102.         $this->addCompilerPassIfExists($containerTranslationExtractorPass::class);
  103.         $this->addCompilerPassIfExists($containerTranslationDumperPass::class);
  104.         $container->addCompilerPass(new FragmentRendererPass());
  105.         $this->addCompilerPassIfExists($containerSerializerPass::class);
  106.         $this->addCompilerPassIfExists($containerPropertyInfoPass::class);
  107.         $container->addCompilerPass(new DataCollectorTranslatorPass());
  108.         $container->addCompilerPass(new ControllerArgumentValueResolverPass());
  109.         $container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION32);
  110.         $container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
  111.         $container->addCompilerPass(new CachePoolPrunerPass(), PassConfig::TYPE_AFTER_REMOVING);
  112.         $this->addCompilerPassIfExists($containerFormPass::class);
  113.         $container->addCompilerPass(new WorkflowGuardListenerPass());
  114.         $container->addCompilerPass(new ResettableServicePass());
  115.         $container->addCompilerPass(new RegisterLocaleAwareServicesPass());
  116.         $container->addCompilerPass(new TestServiceContainerWeakRefPass(), PassConfig::TYPE_BEFORE_REMOVING, -32);
  117.         $container->addCompilerPass(new TestServiceContainerRealRefPass(), PassConfig::TYPE_AFTER_REMOVING);
  118.         $this->addCompilerPassIfExists($containerAddMimeTypeGuesserPass::class);
  119.         $this->addCompilerPassIfExists($containerMessengerPass::class);
  120.         $this->addCompilerPassIfExists($containerHttpClientPass::class);
  121.         $this->addCompilerPassIfExists($containerAddAutoMappingConfigurationPass::class);
  122.         $container->addCompilerPass(new RegisterReverseContainerPass(true));
  123.         $container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING);
  124.         if ($container->getParameter('kernel.debug')) {
  125.             $container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION2);
  126.             $container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
  127.             $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
  128.             $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING);
  129.         }
  130.     }
  131.     private function addCompilerPassIfExists(ContainerBuilder $containerstring $classstring $type PassConfig::TYPE_BEFORE_OPTIMIZATIONint $priority 0)
  132.     {
  133.         $container->addResource(new ClassExistenceResource($class));
  134.         if (class_exists($class)) {
  135.             $container->addCompilerPass(new $class(), $type$priority);
  136.         }
  137.     }
  138. }