定制 acairns/radiate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

acairns/radiate

Composer 安装命令:

composer require acairns/radiate

包简介

Radiate event emitter

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

Introduction

Radiate is a package for managing Events.

Basic Usage

Simply create an instance of the Emitter and emit events!

$emitter new Emitter($middleware);
$emitter->emit(new ExampleEvent);

Creating the Emitter

Radiate requires a pipeline of middleware when being created. The main middleware required to invoke listeners is an instance of the InvokeListenerMiddleware class.

use Cairns\Radiate\Emitter;
use Cairns\Radiate\Inflector\HandleMethodInflector;
use Cairns\Radiate\Middleware\InvokeListenerMiddleware;

$invoker = new InvokeListenerMiddleware(
    $registry,
    $locator,
    $inflector
);

$emitter = new Cairns\Radiate\Emitter([
    $invoker
]);

In order to invoke a Listener, the middleware needs to know the available Listeners ($registry), how to create an instance of the subscribed Listeners ($locator) and how to determine which method should be invoked ($inflector).

Registrys

A Registry is a simple class responsible of keeping track all of the subscribed Listeners.

Locators

The responsibility of the locator is to take a Fully Qualified Class Name for a Listener and to return an instance. If you are using a Dependency Injection container, then this is where you want to resolve the concrete instance.

Inflectors

The job of the inflector is to determine which method should be called on a particular Listener given a specific Event. Several Inflectors are provided for common setups.

HandleMethodInflector

The HandleMethodInflector ensures the handle() method is returned. A Listener could look like this:

final class DisableTransporters
{
    public function handle(WarpDriveEngaged $event)
    {
        // Do Something
    }
}

TypehintMethodInflector

The TypehintMethodInflector ensures any method dependent on the type of event is returned. A Listener could look like this:

final class DisableTransporters
{
    public function whenWarpDriveEngaged(WarpDriveEngaged $event)
    {
        // Do Something
    }

    public function whenShieldsWereRaised(ShieldsWereRaised $event)
    {
        // Do Something
    }
}

When using the TypehintMethodInflector, you can define multiple public methods so that the same Listener can respond to different events.

Simple Example

final class WarpDriveEngaged
{
    private $speed;

    public function __construct($speed)
    {
        $this->speed = $speed;
    }

    public function getSpeed()
    {
        return $this->speed;
    }
}

final class DisableTransporters
{
    public function whenWarpDriveIsEngaged(WarpDriveEngaged $event)
    {
        // safety first!
    }
}

$registry = new \Cairns\Radiate\Registry\TypehintedClassRegistry;
$registry->register(DisableTransporters::class);

$locator = new Cairns\Radiate\Locator\InMemoryListenerLocator;
$locator->add(new DisableTransporters);

$invoker = new \Cairns\Radiate\Middleware\InvokeListenerMiddleware(
    $registry,
    $locator,
    new Cairns\Radiate\Inflector\TypehintMethodInflector
);

$emitter = new Cairns\Radiate\Emitter([
    $invoker
]);

$emitter->emit(new WarpDriveEngaged(9));

Inspiration

This library is inspired by:

Contributing

Even though this is just an experiment for now, I'm totally open to ideas. Shoot over a PR!

If you decide to help out, here are some helpful things to check:

Running tests

$ ./vendor/bin/phpunit

Code Sniffer

$ ./vendor/bin/phpcs --standard=PSR2 ./src/

Todo

  • Bump to >=PHP7, update codebase (return types, typehint, etc.)
  • Extract examples into example directory
  • Make registry serialisable, and constructable from a serialised registry

acairns/radiate 适用场景与选型建议

acairns/radiate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57.54k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「event」 「listener」 「emitter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 acairns/radiate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 acairns/radiate 我们能提供哪些服务?
定制开发 / 二次开发

基于 acairns/radiate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-31