I've created a custom plugin SwagStartup in Shopware, and it works by calling an url like "shopware.project/myDemo".
Then I tried to define/use event subscriber in this plugin, following is the code:
<?php
namespace SwagStartup\Subscriber;
use Enlight\Event\SubscriberInterface;
class RoutingSubscriber implements SubscriberInterface
{
public static function getSubscribedEvents(){
return ['Enlight_Controller_Action_PreDispatch' => 'onPreDispatch'];
}
public function onPreDispatch(\Enlight_Event_EventArgs $args){
die('here!');
}
}
And the XML file: Resources/services.xml:
<?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="swag_startup.subscriber.routing_subscriber"
class="SwagStartup\Subscriber\RoutingSubscriber">
<tag name="shopware.event_subscriber"/>
</service>
</services>
</container>
When I called the url like before, I expected to see the output from the die() function, cause I thought the event Enlight_Controller_Action_PreDispatch should have been caught by the subscriber and the funciton onPreDispatch() should have been called - but it was not the case.
What's wrong? Can someone tell me?