Skip to content

Instantly share code, notes, and snippets.

@bakura10 bakura10/test.php
Last active Aug 29, 2015

Embed
What would you like to do?
<?php
// ListenerAggregateInterface would change, and it would have... a static method (yeah yeah):
class UserListenerAggregate implements ListenerAggregateInterface
{
static function getListenersConfiguration()
{
// This would be a standardized configuration
return [
'listeners' => [
'eventName' => [static::class, 'callbackToCall', 2], // 2 is priority
],
'shared_listeners' => [
'identifier' => [
'eventName' => [static::class, 'anotherMethod', 3] // 3 is priority
]
]
];
}
}
// Here is how you wire up in your Module class
class Module
{
public function onBootstrap(MvcEvent $event)
{
$eventManager = $event->getEventManager();
$eventManager->attachAggregate(UserListenerAggregate::class); // Note that there is no instantiation here
}
}
// What the attachAggregate will do is actually something like that:
public function attachAggregate($aggregate)
{
$configuration = $aggregate::getListenersConfiguration();
foreach ($configuration['listeners'] as $eventName => $listeners) {
$this->attachListeners($eventName, $listeners);
}
foreach ($configuration['shared_listeners'] as $identifier => $listeners) {
foreach ($identifiers as $eventName => $listeners) {
$this->attachSharedListeners($identifier, $eventName, $identifiers)
}
}
}
// Now, the problem is that obviously, none of those listeners are instantiated... So what we do is having
// a ListenerPluginManager. This is a standard plugin manager for listeners. So before actually triggering
// the event, we get all the listeners, and initialize them
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.