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 Events\Dispatcher 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', 'App\Events\Test@handle');

Where the class App\Events\Test is

namespace App\Events;

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 Events\Dispatcher@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
}

Events的更多相关文章

  1. ABP(现代ASP.NET样板开发框架)系列之14、ABP领域层——领域事件(Domain events)

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之14.ABP领域层——领域事件(Domain events) ABP是“ASP.NET Boilerplate P ...

  2. Node.js:events事件模块

    Nodejs的大部分核心API都是基于异步事件驱动设计的,所有可以分发事件的对象都是EventEmitter类的实例. 大家知道,由于nodejs是单线程运行的,所以nodejs需要借助事件轮询,不断 ...

  3. Events基本概念----Beginning Visual C#

    span.kw { color: #007020; font-weight: bold; } code > span.dt { color: #902000; } code > span. ...

  4. Delphi控件之---通过编码学习TStringGrid(也会涉及到Panel控件,还有对Object Inspector的控件Events的介绍

    我是参考了万一的博客里面的关于TStringGrid学习的教程,但是我也结合自己的实际操作和理解,加入了一些个人的补充,至少对我有用! 学用TStringGrid之——ColCount.RowCoun ...

  5. SSE: server-sent events

    当客户端需要定时轮询服务器获取一些消息的时候,可以使用 servser-sent events .NET 服务端: public void ProcessRequest(HttpContext con ...

  6. nodejs学习之events的使用

    实用events做个小例子: var mysql = require("mysql"); var Event = require("events").Event ...

  7. nodejs学习之events

    在node里许多对象都发出事件:一个net.Server对象每次一个连接到来,都发出一个事件,一个fs.readStream对象在文件打开时放出一个事件.所有能放出事件的对象都是event.Event ...

  8. XE1:使用SSMS创建Extended Events

    Extended Events 用于取代SQL trace,是SQL Server 追踪系统运行的神器,其创建过程十分简单. 一,创建Extended Events的Session step1,打开N ...

  9. Lind.DDD.Events领域事件介绍

    回到目录 闲话多说 领域事件大叔感觉是最不好讲的一篇文章,所以拖欠了很久,但最终还是在2015年年前(阴历)把这个知识点讲一下,事件这个东西早在C#1.0时代就有了,那时学起来也是一个费劲,什么是委托 ...

  10. Google C++单元测试框架GoogleTest---Extending Google Test by Handling Test Events

    Google TestExtending Google Test by Handling Test Events Google测试提供了一个事件侦听器API,让您接收有关测试程序进度和测试失败的通知. ...

随机推荐

  1. 【JSP】让HTML和JSP页面不缓存从Web服务器上重新获取页面

    用户退出后,如果点击浏览器上的后退按钮,Web应用将不能正确保护受保护的页面——在Session销毁后(用户退出)受保护的JSP页重新在浏览器中显示出来. 然而,如果用户点击返回页面上的任何链接,We ...

  2. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.3.6

    If $A$ is a contraction, show that $$\bex A^*(I-AA^*)^{1/2}=(I-A^*A)^{1/2}A^*. \eex$$ Use this to sh ...

  3. 018如何建立自动化框架 how to bulid the framwork

    本讲包括: 一. objective 二. How to bulid 三. Keyview of frawork (关键视图) 四. conclusion automation framwork:自动 ...

  4. 五个小例子教你搞懂 JavaScript 作用域问题

    众所周知,JavaScript 的作用域和其他传统语言(类C)差别比较大,掌握并熟练运用JavaScript 的作用域知识,不仅有利于我们阅读理解别人的代码,也有助于我们编写自己的可靠代码. 下面笔者 ...

  5. javascript设计模式4

    静态成员是直接通过类对象访问的 var Book=(function(){ var numOfBooks=0; function checkIsbn(isbn){ ... } return funct ...

  6. 【转载】sed命令详解

    [转载自]http://www.cnblogs.com/edwardlost/archive/2010/09/17/1829145.html   sed -i  把后面的操作后的文本输出回原文本   ...

  7. yum cdh4

    cdh4 install for Centos6那个最美的年代,最好的时光,一路梦想,一路流泪,流的不会是懦弱的泪,而是对奋斗的寄于;1,repo配置>>>/etc/yum.repo ...

  8. 13个不容错过的Java项目

    今天我们将整理一大波干货满满的Java示例代码与能力展示素材. GitHub可谓一座程序开发的大宝库,有些素材值得fork,有些则能帮助我们改进自有代码或者学习编程技能.无论如何,开发工作当中我们几乎 ...

  9. [C++]Microsoft Visual Studio (VS)2010 常用快捷键大全

    VAssistX快捷键 Ctrll+Shift+S   快速查找函数位置  VAssistX提供 Shift+Alt+O     快速查找打开单元  VAssistX提供 Alt+O         ...

  10. Objective-C Runtime 运行时之三:方法与消息

    基础数据类型 SEL SEL又叫选择器,是表示一个方法的selector的指针,其定义如下: typedef struct objc_selector *SEL; objc_selector结构体的详 ...