zoukankan      html  css  js  c++  java
  • Events

    Events

    The idea behind Events is the ability to send data, as parameters, to interested Listeners and call them when an Event happens. The Listeners could be a Closure or a static Class Method.

    To note that if the EventsDispatcher does not instantiate a Listener's Class, then the called method must be static.

    Its usage is simple; first, we have to register a Listener, adding:

    use Event;
    
    // Add a Listener to the Event 'test'.
    Event::listen('test', 'AppEventsTest@handle');

    Where the class AppEventsTest is

    namespace AppEvents;
    
    class Test
    {
        public static function handle($message)
        {
            echo $message;
        }
    }

    Then, when the payload is needed, we would fire the Event:

    // Prepare the Event payload.
    $payload = array(
        'Hello, this is an Event!',
    );
    
    // Fire the Event 'test'.
    Event::fire('test', $payload);

    Queued Events

    The Queued Events is a method to add a number of Events to a Queue, then firing them together, flushing the Queue. E.g

    // Queue the Events
    Event::queue('test', array('This is the First Event'));
    Event::queue('test', array('This is the Second Event'));
    Event::queue('test', array('This is the Third Event'));
    
    // Flush the Queue, firing all defined Events
    Event::flush('test');

    until() Method

    The new method EventsDispatcher@until is about not firing an Event until the first Listener returns a valid and non-null response.

    Its usage is simple:

    $response = Event::until('testing', $payload);
    
    if($response !== null) {
        // Do something with $response
    }
  • 相关阅读:
    不规则的组合方向键或功能键
    jQuery总结
    jQuery 学习
    jquery
    Ubuntu 11.10 (Oneiric)上编译带utrace补丁的内核 转
    linux 内核升级 网址参考
    SSDT&Shadow Hook的实现,完整代码。可编译
    linux信号机制
    linux 内核资料
    PostgreSQL SystemTap on Linux 转
  • 原文地址:https://www.cnblogs.com/chunguang/p/5642988.html
Copyright © 2011-2022 走看看