Custom Events

In easyswoole, custom events can be implemented through the Container

Add 'App/Event/Event.php' file

namespace App\Event;

use EasySwoole\Component\Container;
use EasySwoole\Component\Singleton;

class Event extends Container
    use Singleton;
    function set($key, $item)
        if (is_callable($item)){
            return parent::set($key, $item);
            return false;

    function hook($event,...$arg){
        $call = $this->get($event);
        if (is_callable($call)){
            return call_user_func($call,...$arg);
            return null;

Register events in the initialize event of the framework:

 public static function initialize()
        // TODO: Implement initialize() method.
        \App\Event\Event::getInstance()->set('test', function () {
            echo 'test event';

Call anywhere else:


Can trigger events