|
15 | 15 | use Symfony\Component\HttpFoundation\Response;
|
16 | 16 | use Symfony\Component\HttpKernel\HttpKernelInterface;
|
17 | 17 | use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
| 18 | +use Symfony\Component\HttpKernel\KernelEvents; |
| 19 | +use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
| 20 | +use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
18 | 21 |
|
19 | 22 | /**
|
20 | 23 | * Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel.
|
|
24 | 27 | class InlineFragmentRenderer extends RoutableFragmentRenderer
|
25 | 28 | {
|
26 | 29 | private $kernel;
|
| 30 | + private $dispatcher; |
27 | 31 |
|
28 | 32 | /**
|
29 | 33 | * Constructor.
|
30 | 34 | *
|
31 | 35 | * @param HttpKernelInterface $kernel A HttpKernelInterface instance
|
32 | 36 | */
|
33 |
| - public function __construct(HttpKernelInterface $kernel) |
| 37 | + public function __construct(HttpKernelInterface $kernel, EventDispatcherInterface $dispatcher = null) |
34 | 38 | {
|
35 | 39 | $this->kernel = $kernel;
|
| 40 | + $this->dispatcher = $dispatcher; |
36 | 41 | }
|
37 | 42 |
|
38 | 43 | /**
|
@@ -61,6 +66,14 @@ public function render($uri, Request $request, array $options = array())
|
61 | 66 | try {
|
62 | 67 | return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
|
63 | 68 | } catch (\Exception $e) {
|
| 69 | + // we dispatch the exception event to trigger the logging |
| 70 | + // the response that comes back is simply ignored |
| 71 | + if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) { |
| 72 | + $event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e); |
| 73 | + |
| 74 | + $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event); |
| 75 | + } |
| 76 | + |
64 | 77 | // let's clean up the output buffers that were created by the sub-request
|
65 | 78 | while (ob_get_level() > $level) {
|
66 | 79 | ob_get_clean();
|
|
0 commit comments