switon/event

Class-based synchronous PSR-14 dispatch with attribute-discovered listeners for Switon Framework

Maintainers

Package info

github.com/switon-php/event

Documentation

pkg:composer/switon/event

Statistics

Installs: 75

Dependents: 31

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 01:51:01 UTC


README

CI PHP 8.3+

Switon's PSR-14 event package for application dispatch, listener discovery, and event logging.

Highlights

  • Wildcard listeners: one listener can handle every event with object.
  • Attribute-based listeners: #[EventListener] registers listener methods.
  • Automatic listener discovery: app scan paths and extra.switon.listeners entries are included.
  • Event log level: events can carry a default PSR-3 level.
  • Early-stop support: listeners can halt the remaining chain when needed.
  • Automatic event logging: events can be logged automatically with structured output.

Installation

composer require switon/event

Quick Start

use Psr\EventDispatcher\EventDispatcherInterface;
use Switon\Core\Attribute\Autowired;
use Switon\Eventing\Attribute\EventListener;

final class UserRegistered
{
    public function __construct(public int $userId, public string $email)
    {
    }
}

class UserService
{
    #[Autowired] protected EventDispatcherInterface $eventDispatcher;

    public function register(string $email): void
    {
        $this->eventDispatcher->dispatch(new UserRegistered(123, $email));
    }
}

class UserListener
{
    #[EventListener]
    public function onUserRegistered(UserRegistered $event): void
    {
        // react to the event
    }
}

Docs: https://docs.switon.dev/latest/event

License

MIT.