4b3e218b85c5826d28a6a7493da45c497e290155
[yaffs-website] / vendor / symfony / http-kernel / DependencyInjection / ContainerAwareHttpKernel.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\DependencyInjection;
13
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;
22
23 /**
24  * Adds a managed request scope.
25  *
26  * @author Fabien Potencier <fabien@symfony.com>
27  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
28  *
29  * @deprecated since version 2.7, to be removed in 3.0.
30  */
31 class ContainerAwareHttpKernel extends HttpKernel
32 {
33     protected $container;
34
35     /**
36      * Constructor.
37      *
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
43      */
44     public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver, RequestStack $requestStack = null, $triggerDeprecation = true)
45     {
46         parent::__construct($dispatcher, $controllerResolver, $requestStack);
47
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);
50         }
51
52         $this->container = $container;
53
54         // the request scope might have been created before (see FrameworkBundle)
55         if (!$container->hasScope('request')) {
56             $container->addScope(new Scope('request'));
57         }
58     }
59
60     /**
61      * {@inheritdoc}
62      */
63     public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
64     {
65         $this->container->enterScope('request');
66         $this->container->set('request', $request, 'request');
67
68         try {
69             $response = parent::handle($request, $type, $catch);
70         } catch (\Exception $e) {
71             $this->container->set('request', null, 'request');
72             $this->container->leaveScope('request');
73
74             throw $e;
75         } catch (\Throwable $e) {
76             $this->container->set('request', null, 'request');
77             $this->container->leaveScope('request');
78
79             throw $e;
80         }
81
82         $this->container->set('request', null, 'request');
83         $this->container->leaveScope('request');
84
85         return $response;
86     }
87 }