8000 [Kernel] Mention extra interfaces in `MicroKernel` section · symfony/symfony-docs@996ab53 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 996ab53

Browse files
HeahDudejaviereguiluz
authored andcommitted
[Kernel] Mention extra interfaces in MicroKernel section
1 parent fd4cd2a commit 996ab53

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

configuration/micro_kernel_trait.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,44 @@ 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 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+
105143
Advanced Example: Twig, Annotations and the Web Debug Toolbar
106144
-------------------------------------------------------------
107145

service_container/compiler_passes.rst

Lines changed: 2 additions & 0 deletions
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)
0