Download the PHP package inhere/event without Composer

On this page you can find all versions of the php package inhere/event. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package event

Event Dispatcher

Php Version Latest Stable Version

EN README

简洁, 功能完善的事件管理调度实现

项目地址

安装

事件调度器

事件调度器, 也可称之为事件管理器。事件的注册、监听器注册、调度(触发)都是由它管理的。

事件监听器

监听器允许是:

  1. function 函数
  2. 一个闭包
  3. 一个监听器类(可以有多种方式)

1. function

2. 闭包

3. 监听器类(有多种方式)

此种方式可以在类里面写多个事件的处理方法

此时这个类对象就相当于一个闭包

触发时会自动调用 handle() 方法。

可以在一个类里面自定义监听多个事件

快速使用

1. 绑定事件触发

2. 触发事件

3. 运行示例

完整的实例代码在 examples/demo.php 中。

运行: php examples/demo.php

输出:

一组事件的监听器

除了一些特殊的事件外,在一个应用中,大多数事件是有关联的,此时我们就可以对事件进行分组,方便识别和管理使用。

例如:

1. 一个简单的示例应用类

2. 此应用的监听器类

将每个事件的监听器写一个类,显得有些麻烦。我们可以只写一个类用里面不同的方法来处理不同的事件。

这种方式简单快捷,但是有一定的限制 - 事件名与方法的名称必须相同。

有时候我们并不想将处理方法定义成事件名称一样,想自定义。

此时我们可以实现接口 EventSubscriberInterface,通过里面的 getSubscribedEvents() 来自定义事件和对应的处理方法

运行示例请看 examples/enum-group.php

3. 添加监听

4. 运行示例

完整的示例代码在 examples/named-group.php 中。

运行: php examples/named-group.php

输出:

事件通配符 *

支持使用事件通配符 * 对一组相关的事件进行监听, 分两种。

  1. * 全局的事件通配符。直接对 * 添加监听器($em->attach('*', 'global_listener')), 此时所有触发的事件都会被此监听器接收到。
  2. {prefix}.* 指定分组事件的监听。eg $em->attach('db.*', 'db_listener'), 此时所有触发的以 db. 为前缀的事件(eg db.query db.connect)都会被此监听器接收到。

当然,你在事件到达监听器前停止了本次事件的传播$event->stopPropagation(true);,就不会被后面的监听器接收到了。

示例,在上面的组事件监听器改下,添加一个 app.* 的事件监听。

运行示例

运行: php examples/named-group.php 输出:(可以看到每个事件都经过了AppListener::allEvent()的处理)

事件对象

事件对象 - 装载了在触发事件时相关的上下文信息,用户自定义的。

预先创建一个事件

这样你可以追加自定义数据

License

MIT


All versions of event with dependencies

PHP Build Version
Package Version
Requires php Version >7.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package inhere/event contains the following files

Loading the files please wait ....