@@ -102,6 +102,44 @@ 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 App\Exception\Danger;
118
+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
119
+ use Symfony\Component\HttpKernel\Event\ExceptionEvent;
120
+ use Symfony\Component\HttpKernel\KernelEvents;
121
+
122
+ class Kernel extends BaseKernel implements EventSubscriberInterface
123
+ {
124
+ use MicroKernelTrait;
125
+
126
+ // ...
127
+
128
+ public function onKernelException(ExceptionEvent $event): void
129
+ {
130
+ if ($event->getException() instanceof Danger) {
131
+ $event->setResponse(new Response('It\'s dangerous to go alone. Take this ⚔'));
132
+ }
133
+ }
134
+
135
+ public static function getSubscribedEvents(): array
136
+ {
137
+ return [
138
+ KernelEvents::EXCEPTION => 'onKernelException',
139
+ ];
140
+ }
141
+ }
142
+
105
143
Advanced Example: Twig, Annotations and the Web Debug Toolbar
106
144
-------------------------------------------------------------
107
145
0 commit comments