Add GNU Terry Pratchett to your Symfony 6 project

Add GNU Terry Pratchett to your Symfony 6 project

Add GNU Terry Pratchett to your Symfony 6 project

1 Comment on Add GNU Terry Pratchett to your Symfony 6 project 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

Related Posts

1 Comment

Leave a Reply

Back to Top