PHP code example of sinergi / event

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

    

sinergi / event example snippets


use Sinergi\Event\ListenerInterface;

class MyListener implements ListenerInterface
{
    public function onUpdate(Subject $subject)
    {
        // do something
    }
}

class Subject
{
    public $dispatcher;

    public function update()
    {
        $this->dispatcher->trigger($this, 'update');
    }
}

use Sinergi\Event\Dispatcher;

$dispatcher = new Dispatcher();
$dispatcher->add(new MyListener());

$subject = new Subject();
$subject->dispatcher = $dispatcher;
$subject->update();