FrameworkBundle.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\AddSecurityVotersPass;
  16. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConverterManagerPass;
  17. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
  18. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
  19. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToCachePass;
  20. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
  21. use Symfony\Component\DependencyInjection\ContainerBuilder;
  22. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  23. use Symfony\Component\HttpFoundation\File\File;
  24. use Symfony\Component\HttpKernel\Bundle\Bundle;
  25. /**
  26. * Bundle.
  27. *
  28. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  29. */
  30. class FrameworkBundle extends Bundle
  31. {
  32. /**
  33. * Boots the Bundle.
  34. */
  35. public function boot()
  36. {
  37. $container = $this->container;
  38. if ($container->has('error_handler')) {
  39. $container->get('error_handler');
  40. }
  41. if ($this->container->hasParameter('document_root')) {
  42. File::setDocumentRoot($this->container->getParameter('document_root'));
  43. }
  44. // the session ID should always be included in the CSRF token, even
  45. // if default CSRF protection is not enabled
  46. if ($container->has('form.default_context') && $container->has('session')) {
  47. $addSessionId = function () use ($container) {
  48. // automatically starts the session when the CSRF token is
  49. // generated
  50. $container->get('session')->start();
  51. return $container->get('session')->getId();
  52. };
  53. // $container->getDefinition('form.default_context')
  54. // ->addMethodCall('addCsrfSecret', array($addSessionId));
  55. //
  56. // var_dump($container->getDefinition('form.default_context'));
  57. }
  58. }
  59. public function registerExtensions(ContainerBuilder $container)
  60. {
  61. parent::registerExtensions($container);
  62. $container->addCompilerPass(new AddSecurityVotersPass());
  63. $container->addCompilerPass(new ConverterManagerPass());
  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 TranslatorPass());
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function getNamespace()
  77. {
  78. return __NAMESPACE__;
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function getPath()
  84. {
  85. return strtr(__DIR__, '\\', '/');
  86. }
  87. }