So I'm working with a software made with symfony and vue (shopware). I want to create a plugin that checks the link that the user requested and, if it contains a specific word, I want to show the user a pop-up. I have made a subscriber and I'm dumping the data, but I get nothing in the debug tools?
<?php declare(strict_types=1);
namespace QRLinker\Subscriber;
use Shopware\Storefront\Page\PageLoadedEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class QRLinkerSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
PageLoadedEvent::class => 'onPageLoaded',
];
}
public function onPageLoaded (PageLoadedEvent $event)
{
dump($event);
dump($event->getRequest());
// GET https://dev.example.com/?qr=hubi
// dump($request->query->get('qr'));
}
}
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="QRLinker\Subscriber\QRLinkerSubscriber" >
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
CodePudding user response:
This code works:
<?php declare(strict_types=1);
namespace QRLinker\Subscriber;
use Shopware\Storefront\Page\PageLoadedEvent;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class QRLinkerSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
GenericPageLoadedEvent::class => 'onPageLoaded',
];
}
public function onPageLoaded (PageLoadedEvent $event)
{
// GET https://dev.example.com/?qr=hubi
dump($event->getRequest()->query->get('qr'));
// $event->getRequest()->query->get('qr');
// echo "shit";
}
}