fyre/event 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

fyre/event

Composer 安装命令:

composer require fyre/event

包简介

An event library.

README 文档

README

FyreEvent is a free, open-source events library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/event

In PHP:

use Fyre\Event\EventManager;

Basic Usage

  • $parentEventManager is an EventManager that will handle propagated events, and will default to null.
$eventManager = new EventManager($parentEventManager);

Methods

Add Listener

Add an EventListener.

$eventManager->addListener($eventListener);

Clear

Clear all events.

$eventManager->clear();

Dispatch

Dispatch an Event.

$eventManager->dispatch($event);

Has

Check if an event exists.

  • $name is a string representing the event name.
$hasEvent = $eventManager->has($name);

Off

Remove event(s).

  • $name is a string representing the event name.
  • $callback is the callback to remove.
$eventManager->off($name, $callback);

If the $callback argument is omitted, all events will be removed instead.

$eventManager->off($name);

On

Add an event.

  • $name is a string representing the event name.
  • $callback is the callback to execute.
  • $priority is a number representing the callback priority, and will default to EventManager::PRIORITY_NORMAL.
$eventManager->on($name, $callback, $priority);

Remove Listener

Remove an EventListener.

$eventManager->removeListener($eventListener);

Trigger

Trigger an event.

  • $name is a string representing the event name.

Any additional arguments supplied will be passed to the event callback.

$event = $eventManager->trigger($name, ...$args);

Events

use Fyre\Event\Event;
  • $name is a string representing the name of the Event .
  • $subject is an object representing the Event subject, and will default to null.
  • $data is an array containing the Event data, and will default to [].
  • $cancelable is a boolean indicating whether the event can be cancelled, and will default to true.
$event = new Event($name, $subject, $data, $cancelable);

Get Data

Get the Event data.

$data = $event->getData();

Get Name

Get the Event name.

$name = $event->getName();

Get Result

Get the Event result.

$result = $event->getResult();

Get Subject

Get the Event subject.

$subject = $event->getSubject();

Is Default Prevented

Determine whether the default Event should occur.

$isDefaultPrevented = $event->isDefaultPrevented();

Is Propagation Stopped

Determine whether the Event propagation was stopped.

$isPropagationStopped = $event->isPropagationStopped();

Prevent Default

Prevent the default Event.

$event->preventDefault();

Set Data

  • $data is an array containing the Event data.
$event->setData($data);

Set Result

  • $result is the Event result.
$event->setResult($result);

Stop Propagation

Stop the Event propagating.

$event->stopPropagation();

Event Listeners

Custom event listeners can be created by implementing the Fyre\Event\EventListenerInterface, ensuring all below methods are implemented.

use Fyre\Event\EventListenerInterface;

class MyListener implements EventListenerInterface
{

}

Implemented Events

Get the implemented events.

$events = $listener->implementedEvents();

Event Dispatchers

Custom event dispatchers can be created by using the Fyre\Event\EventDispatcherTrait.

use Fyre\Event\EventDispatcherTrait;

class MyDispatcher
{
    use EventDispatcherTrait;
}

Dispatch Event

Dispatch an Event.

  • $name is a string representing the event name.
  • $data is an array containing the Event data, and will default to [].
  • $subject is an object representing the Event subject, and will default to the event dispatcher.
  • $cancelable is a boolean indicating whether the event can be cancelled, and will default to true.
$this->dispatchEvent($name, $data, $subject, $cancelable);

Get Event Manager

Get the EventManager.

$eventManager = $this->getEventManager();

Set Event Manager

Set the EventManager.

  • $eventManager is an EventManager.
$this->setEventManager($eventManager);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固