Drupal investigation

ContainerAwareHttpKernel.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\Component\HttpKernel\DependencyInjection;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\HttpKernel\HttpKernelInterface;
  14. use Symfony\Component\HttpKernel\HttpKernel;
  15. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  16. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  17. use Symfony\Component\DependencyInjection\ContainerInterface;
  18. use Symfony\Component\DependencyInjection\Scope;
  19. /**
  20. * Adds a managed request scope.
  21. *
  22. * @author Fabien Potencier <fabien@symfony.com>
  23. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  24. *
  25. * @deprecated since version 2.7, to be removed in 3.0.
  26. */
  27. class ContainerAwareHttpKernel extends HttpKernel
  28. {
  29. protected $container;
  30. /**
  31. * Constructor.
  32. *
  33. * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
  34. * @param ContainerInterface $container A ContainerInterface instance
  35. * @param ControllerResolverInterface $controllerResolver A ControllerResolverInterface instance
  36. * @param RequestStack $requestStack A stack for master/sub requests
  37. * @param bool $triggerDeprecation Whether or not to trigger the deprecation warning for the ContainerAwareHttpKernel
  38. */
  39. public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver, RequestStack $requestStack = null, $triggerDeprecation = true)
  40. {
  41. parent::__construct($dispatcher, $controllerResolver, $requestStack);
  42. if ($triggerDeprecation) {
  43. @trigger_error('The '.__CLASS__.' class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Component\HttpKernel\HttpKernel class instead.', E_USER_DEPRECATED);
  44. }
  45. $this->container = $container;
  46. // the request scope might have been created before (see FrameworkBundle)
  47. if (!$container->hasScope('request')) {
  48. $container->addScope(new Scope('request'));
  49. }
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  55. {
  56. $this->container->enterScope('request');
  57. $this->container->set('request', $request, 'request');
  58. try {
  59. $response = parent::handle($request, $type, $catch);
  60. } catch (\Exception $e) {
  61. $this->container->set('request', null, 'request');
  62. $this->container->leaveScope('request');
  63. throw $e;
  64. } catch (\Throwable $e) {
  65. $this->container->set('request', null, 'request');
  66. $this->container->leaveScope('request');
  67. throw $e;
  68. }
  69. $this->container->set('request', null, 'request');
  70. $this->container->leaveScope('request');
  71. return $response;
  72. }
  73. }