PHP code example of yiiboot / event-dispatcher

1. Go to this page and download the library: Download yiiboot/event-dispatcher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yiiboot / event-dispatcher example snippets


return [
    // ...
    'yiiboot/attributed' => [
        'paths' => [
            // ...
            dirname(__DIR__) . '/src/EventListener',
        ]
    ]
];

namespace App\EventListener;

use Yiiboot\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: CustomEvent::class, method: 'onCustomEvent')]
#[AsEventListener(event: FooEvent::class, priority: 42)]
#[AsEventListener(method: 'onBarEvent', group: ['console', 'web'], env: 'prod')]
final class MyMultiListener
{
    public function onCustomEvent(CustomEvent $event): void
    {
        // ...
    }

    public function onFooEvent(FooEvent $event): void
    {
        // ...
    }

    public function onBarEvent(BarEvent $event): void
    {
        // ...
    }

    #[AsEventListener]
    public function onMethodEvent(BarEvent $event): void
    {
        // ...
    }
}