PHP code example of mix / event

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

    

mix / event example snippets


class DatabaseEvent
{
    public $time = 0;
    public $sql = '';
    public $bindings = [];
}

class DatabaseListener implements Mix\Event\ListenerInterface
{

    public function events(): array
    {
        // 要监听的事件数组,可监听多个事件
        return [
            DatabaseEvent::class,
        ];
    }

    public function process(object $event): void
    {
        // 事件触发后,会执行该方法
    }

}

$dispatcher = new Mix\Event\EventDispatcher(new DatabaseListener());

$event = new DatabaseEvent();
$event->time = 10;
$event->sql = 'select * from users';
$dispatcher->dispatch($event);