Add GNU Terry Pratchett to your Symfony 6 project
March 10, 2023
written by Hylke
We all like to put some little personal things in our projects, one that is very small, fun and still harmless, is adding a GNU Terry Pratchett header to every output of your site.
<?php
declare(strict_types=1);
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class GnuClacks implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => 'onResponse',
];
}
public function onResponse(ResponseEvent $event): void
{
$event->getResponse()->headers->set('X-Clacks-Overhead', 'GNU Terry Pratchett');
}
}
To enable it, all you need to do is add the following to your services.yaml
gnu.clacks:
class: App\EventSubscriber\GnuClacks
tags:
- kernel.event_subscriber
This will add the GNU Clacks header to every page. So we never forget about Terry Pratchett
1 Comment
[…] after adding GNU to our Symfony project, I was wondering if it would be just as simple to add to a Spring Boot project, and I found out, it […]