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. 选择select框跳出信息

    <html > <body > <select type="select" name=s1 onChange=alert("你选择了&quo ...

  2. 引用的时候js不能使用虚拟路劲,调试时用排除法测试

    今天碰到2个问题,搞了半天都没明白,又不报错: 就是js的问题:-->我返回了一个json,返回的json是正确的,但是view页面接受不到这个虚拟对象. 完全懵了,不知道为什么view页面接受 ...

  3. C++基类和派生类之间的转换

    本文讲解内容的前提是派生类继承基类的方式是公有继承,关键字public 以下程序为讲解用例. #include<iostream> using namespace std; class A ...

  4. 为Virtualbox中的Solaris10安装VBoxAdditions

    安装增强插件,以便能够和虚拟机拖放文件 1.启动虚拟系统,选择安装VirtualBox增强功 能(Guest Additions).在VirtualBox中选择“设备”->“安装增强功能”.Vi ...

  5. bzoj 1411 [ZJOI2009]硬币游戏

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1411 [题意] N个硬币放在一个有2*N个位置的圆桌上,求T次操作后的情况.对于一个操 ...

  6. HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)

    题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 #include<cstdio> #include<cstr ...

  7. 【Linux 命令】Linux系统下强制用户下线——who,pkill

    [日期]2014年11月18日 [平台]Centos 6.5 [工具]who pkill [步骤] 1)准备工作 以root身份登录. 2)执行who命令,查看有哪些用户已登录到当前主机

  8. 异常(Exception)

    1.Java中所有的异常类都会直接或间接地继承自Exception. 2.RuntimeException类也是直接继承自Exception类,它叫做运行时异常,Java中所有的运行时异常都会直接或间 ...

  9. SGU223 - Little Kings(状态压缩DP)

    题目大意 给定一个N*N(n<=10,k<=n*n)大小的棋盘,要求你在棋盘上放置k个国王,使得不会相互攻击,如果棋盘上某个格子放置了一个国王,那么与他相邻的八个格子都是他的攻击范围,问有 ...

  10. 11个高级MySQL数据库面试问题和答案

    因为有大家的支持,我们才能做到现在,感谢你们这一路上对我们的支持.在这篇文章中,我们将主要针对MySQL的实用技巧,讲讲面试中相关的问题. 1. 如何使用SELECT语句找到你正在运行的服务器的版本并 ...