HttpKernel.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Symfony\Component\HttpKernel;
  3. use Symfony\Component\EventDispatcher\EventDispatcher;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpKernel\HttpKernelInterface;
  8. /*
  9. * This file is part of the Symfony package.
  10. *
  11. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  12. *
  13. * For the full copyright and license information, please view the LICENSE
  14. * file that was distributed with this source code.
  15. */
  16. /**
  17. * HttpKernel notifies events to convert a Request object to a Response one.
  18. *
  19. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  20. */
  21. class HttpKernel extends BaseHttpKernel
  22. {
  23. protected $container;
  24. /**
  25. * Constructor
  26. *
  27. * @param ContainerInterface $container An ContainerInterface instance
  28. * @param EventDispatcher $dispatcher An event dispatcher instance
  29. * @param ControllerResolverInterface $resolver A ControllerResolverInterface instance
  30. */
  31. public function __construct(ContainerInterface $container, EventDispatcher $dispatcher, ControllerResolverInterface $resolver)
  32. {
  33. $this->container = $container;
  34. parent::__construct($dispatcher, $resolver);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  40. {
  41. $currentRequest = null;
  42. if (HttpKernelInterface::MASTER_REQUEST === $type) {
  43. $currentRequest = $this->container->get('request');
  44. }
  45. $this->container->set('request', $request);
  46. $response = parent::handle($request, $type, $catch);
  47. if (null !== $currentRequest) {
  48. $this->container->set('request', $currentRequest);
  49. }
  50. return $response;
  51. }
  52. }