Download the PHP package guirong/php-event without Composer

On this page you can find all versions of the php package guirong/php-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 php-event

PHP Validate

Php Version GitHub tag (latest by date) Coverage Status GitHub all releases

一个简洁小巧的php事件监听器。

使用助手函数 event()

项目地址

注意:

  • 版本要求 php >= 5.5.0

    安装

注册事件和监听器

应用中的 \Guirong\Event\Event 服务类为注册所有的事件监听器提供了一个便利的场所。其中, listen 属性包含了所有事件 (键) 以及事件对应的监听器 (值) 的数组。当然,你可以根据应用的需要,添加多个事件到 listen 属性包含的数组中。你可以直接使用此类作为服务提供者,也可以继承它(建议)。 举个例子,让我们来定义一个新的服务提供者,并来添加一个 OrderPayed 事件:

定义事件

定义监听器

NotifyBuyerListener 监听器:

NotifyShopListener 监听器:

分发事件

助手函数 event()

EventService 服务类由 Guirong\Event\Container 容器创建并接管,不会重复创建实例 假如你觉得事件分发时每次都要传入服务类不方便,可以自己定一个简单的助手函数,引入当前的项目中

事件订阅者

事件订阅者是可以在自身内部订阅多个事件处理器(事件类),订阅者定义的 subscribe 方法接收一个事件分发器实例。你可以调用对应事件分发器上的 listen 方法来注册事件监听器:

定义事件

UserRegister 事件:

UserDestory 事件:

注册事件订阅者

在编写完订阅者之后,就可以通过事件分发器对订阅者进行注册。你可以在 EventService 中的 $subscribe 属性中注册订阅者。例如,让我们将 UserEventSubscriber 添加到数组列表中:

分发事件

使用助手函数 event()

手动注册事件

事件通常是在你服务类 EventService$listen 数组中注册;然而,你也可以在 EventServiceregister 方法中手动注册基于闭包的这些事件:

分发事件

结语

本文的事件系统只是一种代码解耦的写法,并非工具性的依赖包,感兴趣的话可以自己任意扩展。

License

MIT

我的其他项目

guirong/cli-message github

一个简单易用的,命令行输出样式工具库

guirong/php-router github

轻量且快速的路由库

guirong/php-closure github

闭包的序列化和反序列化类库

guirong/php-validate github

一个轻量级且功能丰富的验证和过滤库


All versions of php-event with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.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 guirong/php-event contains the following files

Loading the files please wait ....