src/Viserio/Component/Events/EventManager.php
public function detach(string $eventName, $listener): bool
    {
        $this->validateEventName($eventName);

        if ($this->hasWildcards($eventName)) {
            $this->removeListenerPattern($eventName, $listener);

            return true;
        }

        if (\count($this->getListeners($eventName)) === 0) {
            return false;
        }

        if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
            $listener[0] = $listener[0]();
        }

        $bool = false;

        foreach ($this->listeners[$eventName] as $priority => $listeners) {
            foreach ($listeners as $key => $value) {
                if ($listener !== $value && \is_array($value) && isset($value[0]) && $value[0] instanceof Closure) {
                    $value[0] = $value[0]();
                }

                if ($value === $listener) {
                    unset($listeners[$key], $this->sorted[$eventName]);

                    $bool = true;
                } else {
                    $listeners[$key] = $value;
                }
            }

            if ($listeners) {
                $this->listeners[$eventName][$priority] = $listeners;
            } else {
                unset($this->listeners[$eventName][$priority]);

                $bool = true;
            }
        }

        return $bool;
    }
public function detach(string $eventName, $listener): bool
    {
        $this->validateEventName($eventName);

        if ($this->hasWildcards($eventName)) {
            $this->removeListenerPattern($eventName, $listener);

            return true;
        }

        if (\count($this->getListeners($eventName)) === 0) {
            return false;
        }

        if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
            $listener[0] = $listener[0]();
        }

        $bool = false;

        foreach ($this->listeners[$eventName] as $priority => $listeners) {
            foreach ($listeners as $key => $value) {
                if ($listener !== $value && \is_array($value) && isset($value[0]) && $value[0] instanceof Closure) {
                    $value[0] = $value[0]();
                }

                if ($value === $listener) {
                    unset($listeners[$key], $this->sorted[$eventName]);

                    $bool = true;
                } else {
                    $listeners[$key] = $value;
                }
            }

            if ($listeners) {
                $this->listeners[$eventName][$priority] = $listeners;
            } else {
                unset($this->listeners[$eventName][$priority]);

                $bool = true;
            }
        }

        return $bool;
    }
{@inheritdoc}