FrameworkBundle.php 3.5 KB

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