FrameworkBundle.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\AddConstraintValidatorsPass;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddFieldFactoryGuessersPass;
  13. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
  14. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass;
  15. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
  16. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
  17. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToCachePass;
  18. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToAutoloadMapPass;
  19. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
  20. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
  21. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
  22. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass;
  23. use Symfony\Component\DependencyInjection\ContainerBuilder;
  24. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  25. use Symfony\Component\DependencyInjection\Scope;
  26. use Symfony\Component\HttpFoundation\File\File;
  27. use Symfony\Component\HttpKernel\Bundle\Bundle;
  28. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  29. use Symfony\Component\ClassLoader\MapFileClassLoader;
  30. /**
  31. * Bundle.
  32. *
  33. * @author Fabien Potencier <fabien@symfony.com>
  34. */
  35. class FrameworkBundle extends Bundle
  36. {
  37. /**
  38. * Boots the Bundle.
  39. */
  40. public function boot()
  41. {
  42. // load core classes
  43. ClassCollectionLoader::load(
  44. $this->container->getParameter('kernel.compiled_classes'),
  45. $this->container->getParameter('kernel.cache_dir'),
  46. 'classes',
  47. $this->container->getParameter('kernel.debug'),
  48. true
  49. );
  50. if ($this->container->has('error_handler')) {
  51. $this->container->get('error_handler');
  52. }
  53. if ($this->container->hasParameter('document_root')) {
  54. File::setDocumentRoot($this->container->getParameter('document_root'));
  55. }
  56. if (file_exists($this->container->getParameter('kernel.cache_dir').'/autoload.php')) {
  57. $classloader = new MapFileClassLoader($this->container->getParameter('kernel.cache_dir').'/autoload.php');
  58. $classloader->register(true);
  59. }
  60. }
  61. public function build(ContainerBuilder $container)
  62. {
  63. parent::build($container);
  64. $container->addScope(new Scope('request'));
  65. $container->addCompilerPass(new RoutingResolverPass());
  66. $container->addCompilerPass(new ProfilerPass());
  67. $container->addCompilerPass(new RegisterKernelListenersPass());
  68. $container->addCompilerPass(new TemplatingPass());
  69. $container->addCompilerPass(new AddConstraintValidatorsPass());
  70. $container->addCompilerPass(new AddFieldFactoryGuessersPass());
  71. $container->addCompilerPass(new AddClassesToCachePass());
  72. $container->addCompilerPass(new AddClassesToAutoloadMapPass());
  73. $container->addCompilerPass(new TranslatorPass());
  74. $container->addCompilerPass(new AddCacheWarmerPass());
  75. if ($container->getParameter('kernel.debug')) {
  76. $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING);
  77. $container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
  78. }
  79. }
  80. }