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