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

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