Skip to content

Plugin context within event objects

Compare
Choose a tag to compare
@cjsaylor cjsaylor released this 30 Mar 17:27
· 28 commits to master since this release

This release allows context of a plugin within the event to allow for chaining events in the context of a plugin.

The use would be as follows:

<?php

$pluginManager = new \Zumba\Symbiosis\Plugin\PluginManager(
    '/path/to/plugins',
    '\PluginNamespace'
);
$event = $pluginManager->spawnEvent('event.name', ['data' => 'something']);
$event->trigger();

Or alternatively:

<?php

$pluginManager = new \Zumba\Symbiosis\Plugin\PluginManager(
    '/path/to/plugins',
    '\PluginNamespace'
);
$event = new \Zumba\Symbiosis\Event\Event('event.name', ['data' => 'something']);
$event->setPluginContext($pluginManager)->trigger();

All listeners registered in the plugin would receive the event triggered in both examples. Therefore, if you have an event that needs to be triggered within a plugin, you can trigger off of the event object passed to your listener to continue the chain.