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

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