1: <?php
2: /*************************************************************************************/
3: /* */
4: /* Thelia */
5: /* */
6: /* Copyright (c) OpenStudio */
7: /* email : info@thelia.net */
8: /* web : http://www.thelia.net */
9: /* */
10: /* This program is free software; you can redistribute it and/or modify */
11: /* it under the terms of the GNU General Public License as published by */
12: /* the Free Software Foundation; either version 3 of the License */
13: /* */
14: /* This program is distributed in the hope that it will be useful, */
15: /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16: /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17: /* GNU General Public License for more details. */
18: /* */
19: /* You should have received a copy of the GNU General Public License */
20: /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
21: /* */
22: /*************************************************************************************/
23: namespace Thelia\Core;
24:
25: use Symfony\Component\HttpKernel\HttpKernel;
26: use Symfony\Component\HttpKernel\HttpKernelInterface;
27: use Symfony\Component\HttpFoundation\Request;
28: use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
29: use Symfony\Component\DependencyInjection\ContainerInterface;
30: use Symfony\Component\EventDispatcher\EventDispatcherInterface;
31:
32: /**
33: *
34: * @author Manuel Raynaud <mraynaud@openstudio.fr>
35: */
36:
37: class TheliaHttpKernel extends HttpKernel
38: {
39: public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver)
40: {
41: parent::__construct($dispatcher, $controllerResolver);
42:
43: $this->container = $container;
44: }
45:
46: /**
47: * Handles a Request to convert it to a Response.
48: *
49: * When $catch is true, the implementation must catch all exceptions
50: * and do its best to convert them to a Response instance.
51: *
52: * @param Request $request A Request instance
53: * @param integer $type The type of the request
54: * (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
55: * @param Boolean $catch Whether to catch exceptions or not
56: *
57: * @return Response A Response instance
58: *
59: * @throws \Exception When an Exception occurs during processing
60: *
61: * @api
62: */
63: public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
64: {
65: //$request->headers->set('X-Php-Ob-Level', ob_get_level());
66:
67: $this->container->enterScope('request');
68: $this->container->set('request', $request, 'request');
69:
70: try {
71: $response = parent::handle($request, $type, $catch);
72: } catch (\Exception $e) {
73: $this->container->leaveScope('request');
74:
75: throw $e;
76: }
77:
78: $this->container->leaveScope('request');
79:
80: return $response;
81: }
82: }
83: