承接 krak/event-emitter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

krak/event-emitter

最新稳定版本:v0.1.0

Composer 安装命令:

composer require krak/event-emitter

包简介

Event Emitter

README 文档

README

Simple event emitter package with a lot of flexibility. Inspired by the Evenement library, EventEmitter provides a simple interface for adding and emitting events.

Installation

Install with composer at krak/event-emitter

Usage

<?php

$emitter = Krak\EventEmitter\emitter(); // creates the default emitter instance
$emitter->on('event', function($arg) {
    echo "Hello $arg\n";
});
$emitter->emit('event', "World");

This is the event emitter interface:

<?php

interface EventEmitter {
    public function on($event, $listener);
    public function once($event, $listener);
    public function removeListener($event, $listener);
    public function removeAllListeners($event = null);
    public function listeners($event);
    public function emit($event, ...$arguments);
}

Event Listeners

You can add event listener classes by implementing the EventListener interface.

<?php

use Krak\EventEmitter\EventListener;

class AcmeListener implements EventListener
{
    public function handle($param) {

    }
}

You can then add this into the emitter via:

<?php

$emitter->on('event', new AcmeListener());

Custom Invocation

The default emitter supports custom invocations via the Krak\Invoke library. You can easily pass in a custom invoker which provides flexibility with how your listeners will be invoked.

<?php

use Krak\EventEmitter;

// this creates an emitter that will support container services as listeners
$invoke = new Krak\Invoke\ContainerInvoke(EventEmitter\emitterInvoke(), $container);
$emitter = Krak\EventEmitter\emitter($invoke);
$emitter->on('event', 'service_id');
$emitter->emit('event', 1);

统计信息

  • 总下载量: 186
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固