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

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