Skip to content

Commit 993be9e

Browse files
committed
[Kernel] Mention extra interfaces in MicroKernel section
1 parent c0f4dd4 commit 993be9e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

configuration/micro_kernel_trait.rst

+37
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,43 @@ that define your bundles, your services and your routes:
102102
``RouteCollectionBuilder`` has methods that make adding routes in PHP more
103103
fun. You can also load external routing files (shown below).
104104

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+
105142
Advanced Example: Twig, Annotations and the Web Debug Toolbar
106143
-------------------------------------------------------------
107144

service_container/compiler_passes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Compiler passes are registered in the ``build()`` method of the application kern
3232
}
3333
}
3434

35+
.. _kernel-as-compiler-pass:
36+
3537
One of the most common use-cases of compiler passes is to work with :doc:`tagged
3638
services </service_container/tags>`. In those cases, instead of creating a
3739
compiler pass, you can make the kernel implement

0 commit comments

Comments
 (0)