src/Leevel/Event/Subject.php
public function register($observer): void
    {
        if ($observer instanceof Closure) {
            $observer = new Observer($observer);
        } else {
            if (is_string($observer) &&
                is_string($observer = $this->container->make($observer))) {
                throw new InvalidArgumentException(
                    sprintf('Observer `%s` is invalid.', $observer)
                );
            }

            if (!($observer instanceof SplObserver)) {
                if (!is_callable([$observer, 'handle'])) {
                    throw new InvalidArgumentException(
                        sprintf('Observer `%s` is invalid.', get_class($observer))
                    );
                }

                $observer = new Observer(Closure::fromCallable([$observer, 'handle']));
            }
        }

        $this->attach($observer);
    }
public function register($observer): void
    {
        if ($observer instanceof Closure) {
            $observer = new Observer($observer);
        } else {
            if (is_string($observer) &&
                is_string($observer = $this->container->make($observer))) {
                throw new InvalidArgumentException(
                    sprintf('Observer `%s` is invalid.', $observer)
                );
            }

            if (!($observer instanceof SplObserver)) {
                if (!is_callable([$observer, 'handle'])) {
                    throw new InvalidArgumentException(
                        sprintf('Observer `%s` is invalid.', get_class($observer))
                    );
                }

                $observer = new Observer(Closure::fromCallable([$observer, 'handle']));
            }
        }

        $this->attach($observer);
    }
添加一个观察者角色.

@param \Closure|\SplObserver|string $observer