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 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的更多相关文章
- ABP(现代ASP.NET样板开发框架)系列之14、ABP领域层——领域事件(Domain events)
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之14.ABP领域层——领域事件(Domain events) ABP是“ASP.NET Boilerplate P ...
- Node.js:events事件模块
Nodejs的大部分核心API都是基于异步事件驱动设计的,所有可以分发事件的对象都是EventEmitter类的实例. 大家知道,由于nodejs是单线程运行的,所以nodejs需要借助事件轮询,不断 ...
- Events基本概念----Beginning Visual C#
span.kw { color: #007020; font-weight: bold; } code > span.dt { color: #902000; } code > span. ...
- Delphi控件之---通过编码学习TStringGrid(也会涉及到Panel控件,还有对Object Inspector的控件Events的介绍
我是参考了万一的博客里面的关于TStringGrid学习的教程,但是我也结合自己的实际操作和理解,加入了一些个人的补充,至少对我有用! 学用TStringGrid之——ColCount.RowCoun ...
- SSE: server-sent events
当客户端需要定时轮询服务器获取一些消息的时候,可以使用 servser-sent events .NET 服务端: public void ProcessRequest(HttpContext con ...
- nodejs学习之events的使用
实用events做个小例子: var mysql = require("mysql"); var Event = require("events").Event ...
- nodejs学习之events
在node里许多对象都发出事件:一个net.Server对象每次一个连接到来,都发出一个事件,一个fs.readStream对象在文件打开时放出一个事件.所有能放出事件的对象都是event.Event ...
- XE1:使用SSMS创建Extended Events
Extended Events 用于取代SQL trace,是SQL Server 追踪系统运行的神器,其创建过程十分简单. 一,创建Extended Events的Session step1,打开N ...
- Lind.DDD.Events领域事件介绍
回到目录 闲话多说 领域事件大叔感觉是最不好讲的一篇文章,所以拖欠了很久,但最终还是在2015年年前(阴历)把这个知识点讲一下,事件这个东西早在C#1.0时代就有了,那时学起来也是一个费劲,什么是委托 ...
- Google C++单元测试框架GoogleTest---Extending Google Test by Handling Test Events
Google TestExtending Google Test by Handling Test Events Google测试提供了一个事件侦听器API,让您接收有关测试程序进度和测试失败的通知. ...
随机推荐
- The type or namespace name '****' could not be found (are you missing a using directive or an assembly reference
错误的提升内容:
- 淘宝JAVA中间件Diamond详解(2)-原理介绍
淘宝JAVA中间件Diamond详解(二)---原理介绍 大家好,通过第一篇的快速使用,大家已经对diamond有了一个基本的了解.本次为大家带来的是diamond核心原理的介绍,主要包括server ...
- Linux shell 获取当前时间之前N天
date +%Y%m%d --date '2 days ago' 更多资料关注:www.kootest.com ;技术交流群:182526995
- js基础第八天
返回前面起第一个字符位置 indexOf("sdfsdf");它是从左边索引为0开始数,而且只找第一个,然后返回该字符的位置.返回是个数值.如果找不到该字符,那么就会返回-1. 返 ...
- 卡特兰数 BZOJ3907 网格 NOIP2003 栈
卡特兰数 卡特兰数2 卡特兰数:主要是求排列组合问题 1:括号化矩阵连乘,问多少种方案 2:走方格,不能过对角线,问多少种方案 3:凸边型,划分成三角形 4:1到n的序列进栈,有多少种出栈方案 NOI ...
- 解决OpenCV Error:Insufficient memory(Failed to allocate 1244164 bytes) in unknown function
从师兄那拷贝过来的代码,师兄的机器上可以运行,环境为Win7+OpenCV231,编译器为Debug Win32,拷贝到自己机器上运行时出现问题. 本机的运行环境为win10+OpenCV244,编译 ...
- Java异常的面试问题及答案-Part 1
本文由 ImportNew - 韩远青 翻译自 Journaldev. Java提供了一个健壮的.面向对象的方法来处理出现异常,称为Java异常处理.我以前写过一篇长文章来介绍Java异常处理,今天我 ...
- python 输出字符串如果遇到字典
>>> d = {'a':1} >>> print '%s' % 1,d 1 {'a': 1} >>> print '%s %s' % 1,d T ...
- nyoj 488 素数环
素数环 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 有一个整数n,把从1到n的数字无重复的排列成环,且使每相邻两个数(包括首尾)的和都为素数,称为素数环. 为了简 ...
- 详解struts.multipart.saveDir的临时文件路径
Struts2中的struts.multipart.saveDir主要是用来设置上传文件的临时目录,在不同的配置方式下,它的临时文件目录大有不同,好多人在设置后往往找不到这个临时目录在哪里,下面我就来 ...