PHP code example of smoothphp / eventdispatcher

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

    

smoothphp / eventdispatcher example snippets



use SmoothPhp\Contracts\EventDispatcher\Projection;
use SmoothPhp\EventDispatcher\ProjectEnabledDispatcher;

class MemberRegistered implements Event
{
    ...
}


final class ProjectionOnlyMemberMysqlListener implements Projection
{
    public function handleEvent(MemberRegistered $e)
    {
        db()->insert($e)
    }
}
final class NoneProjectionOnlyMemberThirdPartListener
{
    /** Do not run on reply */
    public function handleEvent(MemberRegistered $e)
    {
        curl()->send($e)
    }
}

$dispatcher = new ProjectEnabledDispatcher();


$dispatcher->addListener('MemberRegistered', [new ProjectionOnlyMemberMysqlListener, 'handleEvent']);
$dispatcher->addListener('MemberRegistered',[new ProjectEnabledDispatcher,'handleEvent']);

$dispatcher->dispatch('MemberRegistered', [],true);