@@ -99,6 +99,44 @@ that define your bundles, your services and your routes:
9999 ``RoutingConfigurator `` has methods that make adding routes in PHP more
100100 fun. You can also load external routing files (shown below).
101101
102+ Adding Interfaces to "Micro" Kernel
103+ -----------------------------------
104+
105+ When using the ``MicroKernelTrait ``, you can also implement the
106+ ``CompilerPassInterface `` to automatically register the kernel itself as a
107+ compiler pass as explained in the dedicated
108+ :ref: `compiler pass section <kernel-as-compiler-pass >`.
109+
110+ It is also possible to implement the ``EventSubscriberInterface `` to handle
111+ events directly from the kernel, again it will be registered automatically::
112+
113+ // ...
114+ use App\Exception\Danger;
115+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
116+ use Symfony\Component\HttpKernel\Event\ExceptionEvent;
117+ use Symfony\Component\HttpKernel\KernelEvents;
118+
119+ class Kernel extends BaseKernel implements EventSubscriberInterface
120+ {
121+ use MicroKernelTrait;
122+
123+ // ...
124+
125+ public function onKernelException(ExceptionEvent $event): void
126+ {
127+ if ($event->getException() instanceof Danger) {
128+ $event->setResponse(new Response('It\'s dangerous to go alone. Take this ⚔'));
129+ }
130+ }
131+
132+ public static function getSubscribedEvents(): array
133+ {
134+ return [
135+ KernelEvents::EXCEPTION => 'onKernelException',
136+ ];
137+ }
138+ }
139+
102140Advanced Example: Twig, Annotations and the Web Debug Toolbar
103141-------------------------------------------------------------
104142
0 commit comments