public function getListeners(string $eventName = null): array
    {
        if ($eventName === null) {
            foreach ($this->listeners as $name => $eventListeners) {
                if (! isset($this->sorted[$name])) {
                    $this->sortListeners($name);
                }
            }

            return \array_filter($this->sorted);
        }

        $this->validateEventName($eventName);

        $this->bindPatterns($eventName);

        if (! isset($this->listeners[$eventName])) {
            return [];
        }

        if (! isset($this->sorted[$eventName])) {
            $this->sortListeners($eventName);
        }

        return $this->sorted[$eventName];
    }