public function detach(EventManagerInterface $events)
    {
        $sharedManager = $events->getSharedManager();

        foreach ($this->listeners as $index => $listeners) {
            if ($listeners === $this) {
                continue;
            }

            if ($listeners instanceof ListenerAggregateInterface) {
                $listeners->detach($events);
            }

            $events->detach($listeners);
        }

        /** @var array $sharedListeners */
        foreach ($this->sharedListeners as $id => $sharedListeners) {
            foreach ($sharedListeners as $index => $listener) {
                if ($listener === $this) {
                    continue;
                }

                if ($listener instanceof ListenerAggregateInterface) {
                    $listener->detach($events);
                }

                $sharedManager->detach($listener, $id);
            }
        }
    }