定制 settermjd/mezzio-eventmanager-integration 二次开发

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

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

settermjd/mezzio-eventmanager-integration

最新稳定版本:0.2.1

Composer 安装命令:

composer require settermjd/mezzio-eventmanager-integration

包简介

This is a small package that simplifies integrating laminas-eventmanager with Mezzio projects built with the Mezzio Skeleton.

README 文档

README

Mezzio / Laminas EventManager Integration

This project provides a simplistic way of integrating laminas-eventmanager with Mezzio projects that are (originally) scaffolded with the Mezzio Skeleton, making it almost trivial to subscribe listeners to events.

Tip

If you're new to Mezzio, check out Mezzio Essentials a practical, hands-on guide, which steps you through how to build an application, from start to finish.

Prerequisites

To use this project, you need the following:

  • Composer installed globally
  • PHP 8.3 or 8.4

Usage

To use the package with an existing Mezzio application, use Composer to add the package as a dependency to your project, as in the following example:

composer require mezzio-eventmanager-integration

How to subscribe listeners to events

Then, to subscribe listeners to events, you need to do two things:

  1. Add a listeners element to the application's configuration, listing the events and the listeners that are subscribed to those events, along with the priority to subscribe them at (which is optional). There are three things to be aware of here:
    • If you don't assign a priority, a listener will be subscribed with a default priority of 1
    • Higher priority values execute earlier
    • Lower (negative) priority values execute later
  2. The listeners must be registered as services in the DI container.

There are many ways to add a listeners element to the application's configuration, but likely the simplest is to create a new file in the config/autoload directory named listeners.global.php, and in that file add a configuration similar to the example below.

<?php

return [
    'listeners' => [
        'add-item' => [
            [
                'listener' => FakeLoggerListener::class,
                'priority' => 10,
            ],
            [
                'listener' => FakeNotificationListener::class,
                'priority' => 20,
            ]
        ],
        'update-item' => [
           [
                'listener' => FakeLoggerListener::class,
           ]
        ],
        'delete-item' => [
            [
                'listener' => FakeNotificationListener::class,
                'priority' => 10,
            ],
        ],
    ],
];

Assuming the configuration above was used:

  • FakeLoggerListener and FakeNotificationListener are subscribed to the "add-item" event
  • FakeLoggerListener is subscribed to the "update-item" with a priority of "1" as a priority was not specified
  • FakeNotificationListener is subscribed to the "delete-item" event

When the "add-item" event is triggered, FakeLoggerListener will execute first as it has a lower priority, then FakeNotificationListener will execute (assuming that execution isn't short-circuited).

Contributing

If you want to contribute to the project, whether you have found issues with it or just want to improve it, here's how:

  • Issues: ask questions and submit your feature requests, bug reports, etc
  • Pull requests: send your improvements

Did You Find The Project Useful?

If the project was useful, and you want to say thank you and/or support its active development, here's how:

  • Add a GitHub Star to the project
  • Write an interesting article about the project wherever you blog

Disclaimer

No warranty expressed or implied. Software is as is.

Made with 🖤 in Bundaberg by Matthew Setter.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-05-02