PHP头条
热点:

PHP实现事件-PHP源码


 $callback, 'once' => $once);
        return true;
    }

    public static function one($event, $callback)
    {
        return self::listen($event, $callback, true);
    }

    public static function remove($event, $index = null)
    {
        if (is_null($index))
            unset(self::$listens[$event]);
        else
            unset(self::$listens[$event][$index]);
    }

    public static function trigger()
    {
        if (!func_num_args()) return;
        $args = func_get_args();
        $event = array_shift($args);
        if (!isset(self::$listens[$event])) return false;
        foreach ((array)self::$listens[$event] as $index => $listen) {
            $callback = $listen['callback'];
            $listen['once'] && self::remove($event, $index);
            call_user_func_array($callback, $args);
        }
    }
}

www.phpzy.comtrue/php/39925.htmlTechArticlePHP实现事件-PHP源码 $callback, once => $once); return true; } public static function one($event, $callback) { return self::listen($event, $callback, true); } public static function remove($event, $index = null) { if (is_null($index))...

相关文章

PHP之友评论

今天推荐