Symfony2 event subscriber does not call listeners
I am trying to set up a simple event subscription based on the example
given here -
http://symfony.com/doc/master/components/event_dispatcher/introduction.html.
Here's my event store:
namespace CookBook\InheritanceBundle\Event;
final class EventStore
{
const EVENT_SAMPLE = 'event.sample';
}
Here's my event subscriber:
namespace CookBook\InheritanceBundle\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
class Subscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
var_dump('here');
return array(
'event.sample' => array(
array('sampleMethod1', 10),
array('sampleMethod2', 5)
));
}
public function sampleMethod1(Event $event)
{
var_dump('Method 1');
}
public function sampleMethod2(Event $event)
{
var_dump('Method 2');
}
}
Here's the config in services.yml:
kernel.subscriber.subscriber:
class: CookBook\InheritanceBundle\Event\Subscriber
tags:
- {name:kernel.event_subscriber}
And here's how I raise the event:
use Symfony\Component\EventDispatcher\EventDispatcher;
use CookBook\InheritanceBundle\Event\EventStore;
$dispatcher = new EventDispatcher();
$dispatcher->dispatch(EventStore::EVENT_SAMPLE);
Expected output:
string 'here' (length=4)
string 'Method 1' (length=8)
string 'Method 2' (length=8)
Actual output:
string 'here' (length=4)
For some reason, the listener methods don't get called. Anyone knows
what's wrong with this code? Thanks.
No comments:
Post a Comment