|
15 | 15 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
16 | 16 | use Symfony\Component\Config\FileLocator;
|
17 | 17 | use Symfony\Component\Console\ConsoleEvents;
|
| 18 | +use Symfony\Component\Console\Event\ConsoleErrorEvent; |
18 | 19 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
19 | 20 | use Symfony\Component\DependencyInjection\Exception\LogicException;
|
20 | 21 | use Symfony\Component\DependencyInjection\Loader;
|
21 | 22 | use Symfony\Component\DependencyInjection\Reference;
|
22 | 23 | use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
| 24 | +use Symfony\Component\HttpKernel\Event\ExceptionEvent; |
23 | 25 | use Symfony\Component\HttpKernel\Kernel;
|
| 26 | +use Symfony\Component\HttpKernel\KernelEvents; |
24 | 27 |
|
25 | 28 | /**
|
26 | 29 | * This is the class that loads and manages your bundle configuration
|
@@ -146,17 +149,37 @@ private function configureErrorListener(ContainerBuilder $container, array $proc
|
146 | 149 | return;
|
147 | 150 | }
|
148 | 151 |
|
| 152 | + $this->tagExceptionListener($container); |
149 | 153 | $this->tagConsoleErrorListener($container);
|
150 | 154 | }
|
151 | 155 |
|
| 156 | + /** |
| 157 | + * BC layer for Symfony < 4.3 |
| 158 | + */ |
| 159 | + private function tagExceptionListener(ContainerBuilder $container): void |
| 160 | + { |
| 161 | + $listener = $container->getDefinition(ErrorListener::class); |
| 162 | + $method = class_exists(ExceptionEvent::class) |
| 163 | + ? 'onException' |
| 164 | + : 'onKernelException'; |
| 165 | + |
| 166 | + $tagAttributes = [ |
| 167 | + 'event' => KernelEvents::EXCEPTION, |
| 168 | + 'method' => $method, |
| 169 | + 'priority' => '%sentry.listener_priorities.console_error%', |
| 170 | + ]; |
| 171 | + |
| 172 | + $listener->addTag('kernel.event_listener', $tagAttributes); |
| 173 | + } |
| 174 | + |
152 | 175 | /**
|
153 | 176 | * BC layer for Symfony < 3.3; see https://symfony.com/blog/new-in-symfony-3-3-better-handling-of-command-exceptions
|
154 | 177 | */
|
155 | 178 | private function tagConsoleErrorListener(ContainerBuilder $container): void
|
156 | 179 | {
|
157 | 180 | $listener = $container->getDefinition(ErrorListener::class);
|
158 | 181 |
|
159 |
| - if (class_exists('Symfony\Component\Console\Event\ConsoleErrorEvent')) { |
| 182 | + if (class_exists(ConsoleErrorEvent::class)) { |
160 | 183 | $tagAttributes = [
|
161 | 184 | 'event' => ConsoleEvents::ERROR,
|
162 | 185 | 'method' => 'onConsoleError',
|
|
0 commit comments