Backend\Core\Installer\ModuleInstaller::subscribeToEvent PHP Метод

subscribeToEvent() публичный Метод

Subscribe to an event, when the subscription already exists, the callback will be updated.
public subscribeToEvent ( string $eventModule, string $eventName, string $module, mixed $callback )
$eventModule string The module that triggers the event.
$eventName string The name of the event.
$module string The module that subscribes to the event.
$callback mixed The callback that should be executed when the event is triggered.
    public function subscribeToEvent($eventModule, $eventName, $module, $callback)
    {
        // build record
        $item['event_module'] = (string) $eventModule;
        $item['event_name'] = (string) $eventName;
        $item['module'] = (string) $module;
        $item['callback'] = serialize($callback);
        $item['created_on'] = gmdate('Y-m-d H:i:s');
        // get db
        $db = $this->getDB();
        // check if the subscription already exists
        $exists = (bool) $db->getVar('SELECT 1
             FROM hooks_subscriptions AS i
             WHERE i.event_module = ? AND i.event_name = ? AND i.module = ?
             LIMIT 1', array($eventModule, $eventName, $module));
        // update
        if ($exists) {
            $db->update('hooks_subscriptions', $item, 'event_module = ? AND event_name = ? AND module = ?', array($eventModule, $eventName, $module));
        } else {
            $db->insert('hooks_subscriptions', $item);
        }
    }