public static function trigger($event_name = NULL, $payload = NULL)
{
if (empty($event_name) || !is_string($event_name) || !array_key_exists($event_name, self::$events)) {
return;
}
foreach (self::$events[$event_name] as $subscriber) {
if (strpos($subscriber['filename'], '.php') === FALSE) {
$subscriber['filename'] .= '.php';
}
$file_path = Modules::file_path($subscriber['module'], $subscriber['filepath'], $subscriber['filename']);
if (!file_exists($file_path)) {
continue;
}
include_once $file_path;
if (!class_exists($subscriber['class'])) {
// if class doesn't exist check that the function is callable
// could be just a helper function
if (is_callable($subscriber['method'])) {
call_user_func($subscriber['method'], $payload);
}
continue;
}
$class = new $subscriber['class']();
if (!is_callable(array($class, $subscriber['method']))) {
unset($class);
continue;
}
$class->{$subscriber['method']}($payload);
unset($class);
}
}