register a event callback
@param string $event event name
@param callable $cb event callback
@param bool $replace replace exists's event cb
@throws \InvalidArgumentException
975679
public function on(string $event, callable $cb, bool $replace = false)
    {
        if (false === ($key = array_search($event, $this->getSupportedEvents(), true))) {
            $sup = implode(',', $this->getSupportedEvents());

            throw new \InvalidArgumentException("The want registered event [$event] is not supported. Supported: $sup");
        }

        // init property
        if ($this->eventHandlers === null) {
            $this->eventHandlers = new \SplFixedArray(\count($this->getSupportedEvents()));
        }

        if (!$replace && isset($this->eventHandlers[$key])) {
            throw new \InvalidArgumentException("The want registered event [$event] have been registered! don't allow replace.");
        }

        $this->eventHandlers[$key] = $cb;
    }
1083178
public function on(string $eventIdentifier, \Closure $callback): void
    {
        $this->eventCallbacks[$eventIdentifier][] = $callback;
    }
117963
public function on ($event, callable $callback)
	{
		if (!isset ($this->events[$event]))
		{
			$this->events[$event] = array ();
		}
		$this->events[$event][] = $callback;
	}
711450
private function checkIfReplaceIncludeMacro(string $replace) : bool
    {
        $keyword_list = self::findMacroKeywords($replace);
        foreach($keyword_list as $keyword){
            $replace = $this->callHandlers($keyword, EnumMacroProcessStorategy::STRATEGY_FISRT);
            if ($replace !== null){
                return true;
            }
        }
        return false;
    }
659306
public function registerEvent($event, $callback)
    {
        $eventManager = $this->getServiceLocator()->get(EventManager::CONFIG_ID);
        $eventManager->attach($event, $callback);
        $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
    }
256812
public static function listen($event, $callback)
	{
		if (!isset(self::$events[$event])) {
			self::$events[$event] = array();
		}
		
		self::$events[$event][] = $callback;
		return true;
	}
1082221
protected function convertEvent($event)
    {
        if ($event instanceof OriginalCallbackEvent) {
            return new CallbackEvent($event);
        }

        if ($event instanceof OriginalEvent) {
            return new Event($event);
        }

        return $event;
    }
327513
protected static function registerObservableEvent($event, $callback)
    {
        if (! isset(static::$dispatcher)) {
            return ;
        }

        $className = get_called_class();

        $event = with(new static())->getObservableKey($event);

        static::$dispatcher->listen("{$event}: {$className}", $callback);
    }
480887
public static function register(self $handler = null, $replace = true)
    {
        if (null === self::$reservedMemory) {
            self::$reservedMemory = str_repeat('x', 10240);
            register_shutdown_function(__CLASS__.'::handleFatalError');
        }

        if ($handlerIsNew = null === $handler) {
            $handler = new static();
        }

        if (null === $prev = set_error_handler(array($handler, 'handleError'))) {
            restore_error_handler();
            // Specifying the error types earlier would expose us to https://bugs.php.net/63206
            set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
            $handler->isRoot = true;
        }

        if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
            $handler = $prev[0];
            $replace = false;
        }
        if ($replace || !$prev) {
            $handler->setExceptionHandler(set_exception_handler(array($handler, 'handleException')));
        } else {
            restore_error_handler();
        }

        $handler->throwAt(E_ALL & $handler->thrownErrors, true);

        return $handler;
    }
735779
def register_callback(self, callback, remove=False):
        """"""

        # (Un)Register the callback.
        if remove and callback in self.callbacks:
            self.callbacks.remove(callback)
        elif not remove and callback not in self.callbacks:
            self.callbacks.append(callback)
85787
public function triggerEvent($event, $args = [])
    {
        if (!($event instanceof EventInterface)) {
            if (isset($this->events[$event])) {
                $event = $this->events[$event];
            } else {
                $event = new Event($event);
            }
        }

        $event->mergeArguments($args);

        if (isset($this->listeners[$event->getName()])) {
            foreach ($this->listeners[$event->getName()] as $listener) {
                if ($event->isStopped()) {
                    return $event;
                }

                if (is_callable($listener)) {
                    call_user_func($listener, $event);
                } else {
                    call_user_func([$listener, $event->getName()], $event);
                }
            }
        }

        return $event;
    }
673113
function triggerModeScriptEvent($event, $params = '', $multicall = false)
    {
        if (!is_string($event)) {
            throw new InvalidArgumentException('event name must be a string: event = ' . print_r($event, true));
        }

        if (is_string($params)) {
            return $this->execute(ucfirst(__FUNCTION__), array($event, $params), $multicall);
        }

        if (is_array($params)) {
            foreach ($params as $param) {
                if (!is_string($param)) {
                    throw new InvalidArgumentException('argument must be a string: param = ' . print_r($param, true));
                }
            }
            return $this->execute(ucfirst(__FUNCTION__) . 'Array', array($event, $params), $multicall);
        }

        // else
        throw new InvalidArgumentException('argument must be string or string[]: params = ' . print_r($params, true));
    }
397477
public function on($event, Closure $callback)
    {
        if (!in_array($event, ['*', 'modify', 'delete', 'create'])) {
            throw new RuntimeException('Could not bind to unknown event '.$event);
        }

        $this->registerBinding($event, $callback);
    }
744599
protected static function registerObservableEvent(string $event, $callback): void
    {
        if (! isset(static::$dispatcher)) {
            return;
        }

        $event = (new static())->getObservableKey($event);

        static::$dispatcher->listen("{$event}: ".static::class, $callback);
    }
78677
public function rename(string $newName, bool $replace = true): bool
    {
        //根据是否覆盖
        $ret = $replace ? $this->handle->rename($this->name, $newName) : $this->handle->renameNx($this->name, $newName);

        //如果改名成功,修改本对象的键
        if ($ret) {
            $this->name = $newName;
        }
        return $ret;
    }
1084483
public function replace($search, $replace): Aggregator
    {
        foreach ($this->elements as $element) {
            if ($element instanceof ReplaceableInterface) {
                $element->replace($search, $replace);
            }
        }

        return $this;
    }
160198
public function registerEvent($event, $callback)
    {
        $name = $this->entityMap->getClass();

        $this->dispatcher->listen("analogue.{$event}.{$name}", $callback);
    }