src/Server/Components/Event/EventDispatcher.php
public function dispatch($type, $data = null, $onlyMyWorker = false, $fromDispatch = false)
    {
        if (!$onlyMyWorker) {
            if ($fromDispatch) {//来自集群的请求
                get_instance()->sendToAllAsynWorks(SwooleMarco::DISPATCHER_NAME, [$type, $data], EventDispatcher::class . "::workerDispatchEventWith");
                return;
            }
            if (get_instance()->isCluster()) {
                ProcessManager::getInstance()->getRpcCall(ClusterProcess::class, true)->my_dispatchEvent($type, $data);
            }
            get_instance()->sendToAllAsynWorks(SwooleMarco::DISPATCHER_NAME, [$type, $data], EventDispatcher::class . "::workerDispatchEventWith");
        } else {//仅仅发布自己的进程
            self::workerDispatchEventWith([$type, $data]);
        }
    }
public function dispatch($type, $data = null, $onlyMyWorker = false, $fromDispatch = false)
    {
        if (!$onlyMyWorker) {
            if ($fromDispatch) {//来自集群的请求
                get_instance()->sendToAllAsynWorks(SwooleMarco::DISPATCHER_NAME, [$type, $data], EventDispatcher::class . "::workerDispatchEventWith");
                return;
            }
            if (get_instance()->isCluster()) {
                ProcessManager::getInstance()->getRpcCall(ClusterProcess::class, true)->my_dispatchEvent($type, $data);
            }
            get_instance()->sendToAllAsynWorks(SwooleMarco::DISPATCHER_NAME, [$type, $data], EventDispatcher::class . "::workerDispatchEventWith");
        } else {//仅仅发布自己的进程
            self::workerDispatchEventWith([$type, $data]);
        }
    }
public function dispatch ( $ type , $ data = null , $ onlyMyWorker = false , $ fromDispatch = false ) { if ( ! $ onlyMyWorker ) { if ( $ fromDispatch ) { //来自集群的请求 get_instance ( ) -> sendToAllAsynWorks ( SwooleMarco :: DISPATCHER_NAME , [ $ type , $ data ] , EventDispatcher :: class . "::workerDispatchEventWith" ) ; return ; } if ( get_instance ( ) -> isCluster ( ) ) { ProcessManager :: getInstance ( ) -> getRpcCall ( ClusterProcess :: class , true ) -> my_dispatchEvent ( $ type , $ data ) ; } get_instance ( ) -> sendToAllAsynWorks ( SwooleMarco :: DISPATCHER_NAME , [ $ type , $ data ] , EventDispatcher :: class . "::workerDispatchEventWith" ) ; } else { //仅仅发布自己的进程 self :: workerDispatchEventWith ( [ $ type , $ data ] ) ; } }
Dispatches an event with the given parameters to all objects that have registered
listeners for the given type.
The method uses an internal pool of event objects to
avoid allocations.

@param string $type
@param null $data
@param bool $onlyMyWorker
@param bool $fromDispatch
@throws \Exception
Dispatches an event with the given parameters to all objects that have registered listeners for the given type . The method uses an internal pool of event objects to avoid allocations .