/** * @param $operation * @param $mixed * @param string $suffix */ function xcom_subscribe($operation, $mixed, $suffix = '') { Xapp_Event::listen(XAPP_EVENT_PREFIX . $operation . $suffix, $mixed); }
/** * constructor initializes options and registers profile listeners according * to the set options * * @error 15201 * @param null|mixed $options expects optional options */ public function __construct($options = null) { xapp_init_options($options, $this); if (xapp_is_option(self::PROFILE_SQL, $this)) { Xapp_Event::listen('xapp.orm.query', function ($sql, $params, $time) { foreach ($params as $p) { $sql = preg_replace('/\\?/i', Xapp_Orm::quote($p), $sql, 1); $sql = htmlspecialchars($sql); } xapp_profile('query', $sql, $time); }); } if (xapp_is_option(self::PROFILE_ERROR, $this)) { Xapp_Event::listen('xapp.error', function ($e) { xapp_profile('error', $e); }); } if (xapp_get_option(self::MODE, $this) === 1 || xapp_get_option(self::MODE, $this) === true) { Xapp_Event::listen('xapp.shutdown', function () { xapp_profile(false); }); } }
/** * resets the whole event listener storage array, all listeners for one event or * listeners for an event at a specific index. the index can be a numerical index or * a value "first" for shifting array one down, or "last" to pop of last. * NOTE: resetting instead of overriding can accidently lead to mal function of xapp * * @error 10405 * @param null|string $event expects event name * @param null|int|string $index expects index value as explained above * @return void * @throws Xapp_Error */ public static function reset($event = null, $index = null) { if ($event !== null) { if (isset(self::$_events[$event])) { if ($index !== null) { if (is_int($index) && array_key_exists($index, self::$_events[$event])) { self::$_events[$event][$index] = array(); } else { if (strtolower((string) $index) === 'first') { array_shift(self::$_events[$event]); } else { if (strtolower((string) $index) === 'last') { array_pop(self::$_events[$event]); } else { throw new Xapp_Error(xapp_sprintf(_("unable to reset listener for event name and index: %s"), $index), 1040501); } } } } else { self::$_events[$event] = array(); } } } else { self::$_events = array(); } }
/** * xapp event trigger/listen shortcut function to (re)delegate re(direct) xapp events. the events are triggered from * inside the xapp framework and can be listened to from everywhere if Xapp_Event class is loaded. the event syntax * is a following (action):(namespace).(event) to trigger events: "trigger:xapp.shutdown", "trigger:myevent", to listen * to events: "listen:xapp.shutdown", "listen:xapp.myevent". the xapp event functionality can be used outside of xapp * framework and new events easily defined and triggered. best to use own events with own namespace like "trigger:my.event". * if this function is overwritten events can be handled with custom logic and redirected. * * overwrite like: * <code> * function xapp_event($event = null, $mixed = null, $bool = false) * { * //your custom code here * } * </code> * * @param null|string $event expects event command as explained above * @param null|callable|array $mixed expects according to event action a callable for listeners or a params array * to be passed to the listener from the trigger * @param boolean $bool expects a boolean value which is used in xapp listener mode to reset listeners for event. * in trigger mode to stop bubbling events. * @return array|mixed|null according to event command */ function xapp_event($event = null, $mixed = null, $bool = false) { if ($event !== null) { if (xapped() && xapped('Xapp_Event')) { if (($pos = strpos($event, ':')) !== false) { $type = strtolower(substr($event, 0, $pos)); $event = substr($event, $pos + 1, strlen($event)); if ($type === 'listen' && is_callable($mixed)) { return Xapp_Event::listen($event, $mixed, $bool); } else { return Xapp_Event::trigger($event, $mixed, $bool); } } else { return Xapp_Event::trigger($event, $mixed, $bool); } } } return null; }