Skip to content

switon-php/event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Switon Event Package

PSR-14 event dispatching and listener discovery for Switon Framework.

Installation

composer require switon/event

Requirements: PHP 8.3+

Development: install dev dependencies before running package tests.

Quick Start

use App\Event\UserCreated;
use Psr\EventDispatcher\EventDispatcherInterface;
use Switon\Core\Attribute\Autowired;
use Switon\Core\Attribute\EventListener;

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

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

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

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

License

MIT.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages