FrameworkBundle.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\AddCacheClearerPass;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
  13. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
  14. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
  15. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
  16. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
  17. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass;
  18. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
  19. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
  20. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
  21. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
  22. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
  23. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
  24. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
  25. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
  26. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
  27. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
  28. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
  29. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
  30. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
  31. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
  32. use Symfony\Component\Debug\ErrorHandler;
  33. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  34. use Symfony\Component\DependencyInjection\ContainerBuilder;
  35. use Symfony\Component\DependencyInjection\Scope;
  36. use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
  37. use Symfony\Component\HttpFoundation\Request;
  38. use Symfony\Component\HttpKernel\Bundle\Bundle;
  39. use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
  40. /**
  41. * Bundle.
  42. *
  43. * @author Fabien Potencier <fabien@symfony.com>
  44. */
  45. class FrameworkBundle extends Bundle
  46. {
  47. public function boot()
  48. {
  49. ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
  50. if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
  51. Request::setTrustedProxies($trustedProxies);
  52. }
  53. if ($this->container->getParameter('kernel.http_method_override')) {
  54. Request::enableHttpMethodParameterOverride();
  55. }
  56. if ($trustedHosts = $this->container->getParameter('kernel.trusted_hosts')) {
  57. Request::setTrustedHosts($trustedHosts);
  58. }
  59. }
  60. public function build(ContainerBuilder $container)
  61. {
  62. parent::build($container);
  63. // we need to add the request scope as early as possible so that
  64. // the compilation can find scope widening issues
  65. $container->addScope(new Scope('request'));
  66. $container->addCompilerPass(new RoutingResolverPass());
  67. $container->addCompilerPass(new ProfilerPass());
  68. // must be registered before removing private services as some might be listeners/subscribers
  69. // but as late as possible to get resolved parameters
  70. $container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
  71. $container->addCompilerPass(new TemplatingPass());
  72. $container->addCompilerPass(new AddConstraintValidatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
  73. $container->addCompilerPass(new AddValidatorInitializersPass());
  74. $container->addCompilerPass(new AddConsoleCommandPass());
  75. $container->addCompilerPass(new FormPass());
  76. $container->addCompilerPass(new TranslatorPass());
  77. $container->addCompilerPass(new LoggingTranslatorPass());
  78. $container->addCompilerPass(new AddCacheWarmerPass());
  79. $container->addCompilerPass(new AddCacheClearerPass());
  80. $container->addCompilerPass(new AddExpressionLanguageProvidersPass());
  81. $container->addCompilerPass(new TranslationExtractorPass());
  82. $container->addCompilerPass(new TranslationDumperPass());
  83. $container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
  84. $container->addCompilerPass(new SerializerPass());
  85. $container->addCompilerPass(new PropertyInfoPass());
  86. $container->addCompilerPass(new DataCollectorTranslatorPass());
  87. if ($container->getParameter('kernel.debug')) {
  88. $container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
  89. $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
  90. $container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
  91. $container->addCompilerPass(new ConfigCachePass());
  92. }
  93. }
  94. }