PHP code example of talesoft / tale-event

1. Go to this page and download the library: Download talesoft/tale-event 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/ */

    

talesoft / tale-event example snippets


use Tale\Event\ListenerProvider\ReflectionListenerProvider;
use Tale\EventDispatcher;

$provider = new ReflectionListenerProvider();
$dispatcher = new EventDispatcher($provider);

class MyEvent
{
    private $message = '';
    
    public function setMessage(string $message): void
    {
        $this->message = $message;
    }
    
    public function getMessage(): string
    {
        return $this->message;
    }
}

$provider->addListener(function (MyEvent $event) {
    $event->setMessage('Hello from listener!');
});

$event = new MyEvent();
$dispatcher->dispatch($event);
echo $event->getMessage(); // "Hello from listener!"