承接 cleup/events 相关项目开发

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

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

cleup/events

最新稳定版本:v1.0.1

Composer 安装命令:

composer require cleup/events

包简介

A convenient event system for modifying and extending the web application platform

README 文档

README

Installation

Install the cleup/events library using composer:

composer require cleup/events

Usage

Event initialization
use Cleup\Components\Events\Event;

# Simple event
Event::apply('customEvent');

# Event with arguments
$name = 'Eduard';
$age = 30;
$fields = array(
    'login' => 'priveted',
    'type' => 'admin'
);
Event::apply('customEvent', $name, $age, $fields, ...);
Add a new event
use Cleup\Components\Events\Event;

# With the function
Event::add('customEvent', function () {
   print_r("Hi, I've been added to the event thread");
});

# Using the function name
function helloWorld () {
    print_r('Hello World!');
}

Event::add('customEvent', 'helloWorld');

# Using the class method
Event::add('customEvent', [Example::class, 'get']);
Modifiers for adding an event

Assign the position of the callback execution.

use Cleup\Components\Events\Event;

Event::add('getPosts', function (&$postList) {
    // ...
})->position(100);

Create an ID for the event. You can use this ID to delete a specific event

use Cleup\Components\Events\Event;

Event::add('getPosts', function (&$postList) {
    // ...
})->id('isBadPost');

Execute once. The modifier can be useful if the event is executed multiple times or in a loop.

use Cleup\Components\Events\Event;

Event::add('postItem', function ($post) {
    // This event will be deleted immediately after execution
})->once();

$posts = array(
    0 => [
        'id' => 1
        'title' => 'First post'
    ],
    1 => [
        'id' => 2
        'title' => 'Hello world!'
    ]
)

foreach($posts as $post) {
    // The event will be executed only once and will be deleted
    Event::apply('postItem', $post);
}
Delete event
Event::delete('getdPosts');

// Delete event by ID
Event::delete('getdPosts', 'isBadPost');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-17