Skip to content

[Kernel] Mention extra interfaces in MicroKernel section #17313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions configuration/micro_kernel_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ that define your bundles, your services and your routes:
``RouteCollectionBuilder`` has methods that make adding routes in PHP more
fun. You can also load external routing files (shown below).

Adding Interfaces to "Micro" Kernel
-----------------------------------

When using the ``MicroKernelTrait``, you can also implement the
``CompilerPassInterface`` to automatically register the kernel itself as a
compiler pass as explained in the dedicated
:ref:`compiler pass section <kernel-as-compiler-pass>`.

It is also possible to implement the ``EventSubscriberInterface`` to handle
events directly from the kernel, again it will be registered automatically::

// ...
use App\Exception\Danger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class Kernel extends BaseKernel implements EventSubscriberInterface
{
use MicroKernelTrait;

// ...

public function onKernelException(ExceptionEvent $event): void
{
if ($event->getException() instanceof Danger) {
$event->setResponse(new Response('It\'s dangerous to go alone. Take this ⚔'));
}
}

public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => 'onKernelException',
];
}
}

Advanced Example: Twig, Annotations and the Web Debug Toolbar
-------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions service_container/compiler_passes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Compiler passes are registered in the ``build()`` method of the application kern
}
}

.. _kernel-as-compiler-pass:

One of the most common use-cases of compiler passes is to work with :doc:`tagged
services </service_container/tags>`. In those cases, instead of creating a
compiler pass, you can make the kernel implement
Expand Down