72 lines
1.6 KiB
Plaintext
72 lines
1.6 KiB
Plaintext
/**
|
|
* event plug-in trigger switch
|
|
*
|
|
* @var boolean
|
|
* @since 3.2.0
|
|
*/
|
|
protected $activePlugins = false;
|
|
|
|
/**
|
|
* The application to trigger and event TODO
|
|
*
|
|
* @since 3.2.0
|
|
*/
|
|
protected $dispatcher;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param Registry|null $params The component parameters
|
|
*
|
|
* @since 3.2.0
|
|
*/
|
|
public function __construct(?Registry $params = null)
|
|
{
|
|
// Set the params
|
|
$params = $params ?: Helper::getParams('com_componentbuilder');
|
|
// get active plugins
|
|
if (($plugins = $params->get('compiler_plugin', false))
|
|
!== false)
|
|
{
|
|
foreach ($plugins as $plugin)
|
|
{
|
|
// get possible plugins
|
|
if (PluginHelper::isEnabled('extension', $plugin))
|
|
{
|
|
// Import the appropriate plugin group.
|
|
PluginHelper::importPlugin('extension', $plugin);
|
|
// activate events
|
|
$this->activePlugins = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->dispatcher = Factory::getApplication();
|
|
}
|
|
|
|
/**
|
|
* Trigger an event
|
|
*
|
|
* @param string $event The event to trigger
|
|
* @param mixed $data The values to pass to the event/plugin
|
|
*
|
|
* @return void
|
|
* @throws \Exception
|
|
* @since 3.2.0
|
|
*/
|
|
public function trigger(string $event, $data = null)
|
|
{
|
|
// only execute if plugins were loaded (active)
|
|
if ($this->activePlugins)
|
|
{
|
|
try
|
|
{
|
|
// Trigger this compiler event.
|
|
$results = $this->dispatcher->triggerEvent($event, $data ?? []);
|
|
}
|
|
catch (\Exception $e)
|
|
{
|
|
throw new \Exception("Error processing event '$event': " . $e->getMessage());
|
|
}
|
|
}
|
|
} |