2017 © Pedro Peláez
 

library event

php的事件类

image

lackone/event

php的事件类

  • Friday, April 27, 2018
  • by lackone
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

event

一个简单的php事件类,用于绑定和解绑事件,触发回调。, (*1)

如何使用

1、引入

composer require lackone/event , (*2)

2、在类中使用trait

use Lackone\Event; , (*3)

3、简单的例子

<?php
require 'vendor/autoload.php';

class Test
{
    use Lackone\Event;

    public static function call0()
    {
        //获取参数
        var_dump(func_get_args());
    }

    public static function call1()
    {
        echo 'call1...<br>';
    }

    public static function call2()
    {
        echo 'call2...<br>';
    }

    public static function call3()
    {
        echo 'call3...<br>';
    }
}

//绑定事件
Test::on('test', ['Test', 'call0']);
//触发事件
Test::trigger('test', ['hello', 'world']);

echo '


'; //设置事件优先级,优先级越大,越先执行 Test::on('pro', ['Test', 'call1'], 1); Test::on('pro', ['Test', 'call2'], 2); Test::on('pro', ['Test', 'call3'], 3); Test::trigger('pro'); echo '
'; //设置一次性事件,只能触发一次 Test::once('one', ['Test', 'call1']); Test::trigger('one'); Test::trigger('one'); echo '
'; //解绑事件 Test::on('off', ['Test', 'call1']); Test::on('off', ['Test', 'call2']); Test::on('off', ['Test', 'call3']); //解绑具体的某个回调 Test::off('off', ['Test', 'call2']); Test::trigger('off');

The Versions

27/04 2018

dev-master

9999999-dev https://github.com/lackone

php的事件类

  Sources   Download

MIT

by Avatar lackone

event

27/04 2018

1.0.0

1.0.0.0 https://github.com/lackone

php的事件类

  Sources   Download

MIT

by Avatar lackone

event