jcb-compiler/src/4729c2b0-f12b-4397-8d77-055.../code.power

72 lines
1.6 KiB
Plaintext
Raw Normal View History

2024-01-27 07:09:33 +00:00
/**
2024-03-14 12:29:20 +00:00
* event plug-in trigger switch
2024-01-27 07:09:33 +00:00
*
* @var boolean
* @since 3.2.0
*/
protected $activePlugins = false;
2024-03-14 12:29:20 +00:00
/**
* The application to trigger and event TODO
*
* @since 3.2.0
*/
protected $dispatcher;
2024-01-27 07:09:33 +00:00
/**
* 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
2024-03-14 12:29:20 +00:00
if (PluginHelper::isEnabled('extension', $plugin))
2024-01-27 07:09:33 +00:00
{
// Import the appropriate plugin group.
2024-03-14 12:29:20 +00:00
PluginHelper::importPlugin('extension', $plugin);
2024-01-27 07:09:33 +00:00
// activate events
$this->activePlugins = true;
}
}
}
2024-03-14 12:29:20 +00:00
$this->dispatcher = Factory::getApplication();
2024-01-27 07:09:33 +00:00
}
/**
2024-03-14 12:29:20 +00:00
* Trigger an event
2024-01-27 07:09:33 +00:00
*
* @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)
{
2024-03-14 12:29:20 +00:00
try
2024-01-27 07:09:33 +00:00
{
2024-03-14 12:29:20 +00:00
// Trigger this compiler event.
$results = $this->dispatcher->triggerEvent($event, $data ?? []);
}
catch (\Exception $e)
{
throw new \Exception("Error processing event '$event': " . $e->getMessage());
2024-01-27 07:09:33 +00:00
}
}
}