4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\DependencyInjection;
14 use Symfony\Component\HttpFoundation\Request;
15 use Symfony\Component\HttpFoundation\RequestStack;
16 use Symfony\Component\HttpKernel\HttpKernelInterface;
17 use Symfony\Component\HttpKernel\HttpKernel;
18 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
19 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20 use Symfony\Component\DependencyInjection\ContainerInterface;
21 use Symfony\Component\DependencyInjection\Scope;
24 * Adds a managed request scope.
26 * @author Fabien Potencier <fabien@symfony.com>
27 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
29 * @deprecated since version 2.7, to be removed in 3.0.
31 class ContainerAwareHttpKernel extends HttpKernel
38 * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
39 * @param ContainerInterface $container A ContainerInterface instance
40 * @param ControllerResolverInterface $controllerResolver A ControllerResolverInterface instance
41 * @param RequestStack $requestStack A stack for master/sub requests
42 * @param bool $triggerDeprecation Whether or not to trigger the deprecation warning for the ContainerAwareHttpKernel
44 public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver, RequestStack $requestStack = null, $triggerDeprecation = true)
46 parent::__construct($dispatcher, $controllerResolver, $requestStack);
48 if ($triggerDeprecation) {
49 @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);
52 $this->container = $container;
54 // the request scope might have been created before (see FrameworkBundle)
55 if (!$container->hasScope('request')) {
56 $container->addScope(new Scope('request'));
63 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
65 $this->container->enterScope('request');
66 $this->container->set('request', $request, 'request');
69 $response = parent::handle($request, $type, $catch);
70 } catch (\Exception $e) {
71 $this->container->set('request', null, 'request');
72 $this->container->leaveScope('request');
75 } catch (\Throwable $e) {
76 $this->container->set('request', null, 'request');
77 $this->container->leaveScope('request');
82 $this->container->set('request', null, 'request');
83 $this->container->leaveScope('request');