Stops listening to an event

@param string|null   $event    name of the event
@param callable|null $callback callback handler

@return EventInterface
423311
public function off(string $event = null, callable $callback = null): EventInterface
    {
        //if there is no event and not callable
        if (is_null($event) && is_null($callback)) {
            //it means that they want to remove everything
            $this->observers = [];
            return $this;
        }

        //if there are callbacks listening to
        //this and no callback was specified
        if (isset($this->observers[$event]) && is_null($callback)) {
            //it means that they want to remove
            //all callbacks listening to this event
            unset($this->observers[$event]);
            return $this;
        }

        //if there are callbacks listening
        //to this and we have a callback
        if (isset($this->observers[$event]) && is_callable($callback)) {
            return $this->removeObserversByEvent($event, $callback);
        }

        //if no event, but there is a callback
        if (is_null($event) && is_callable($callback)) {
            return $this->removeObserversByCallback($callback);
        }

        // @codeCoverageIgnoreStart
        return $this;
        // @codeCoverageIgnoreEnd
    }
573385
public function removeReturnListener(callable $callback)
    {
        foreach ($this->returnCallbacks as $k => $v) {
            if ($v === $callback) {
                unset($this->returnCallbacks[$k]);
            }
        }

        return $this;
    }
232189
public function end(?callable $callback = null): void
    {
        $context =  \array_merge($this->context, [
            'name' => $this->name,
            'started' => $this->startedAt,
            'lapse' => $this->lapse(),
        ]);

        $message = $this->buildMessage($context);

        $this->getLogger()->info($message, $this->context);

        if (\is_callable($callback)) {
            \call_user_func($callback, $message, $context);
        }
    }
973727
public function off($event = null, $callable = null)
    {
         Argument::i()
            //argument 1 must be a string or null
            ->test(1, 'string', 'null')
            //argument 2 must be a callable or null
            ->test(2, 'callable', 'null');

        Event::i()->off($event, $callable);

        return $this;
    }
932761
public function removeListener(
        string $event,
        callable $listener
    )
    {
        if ($this->_events[$event] ?? false) {

            $key = array_search(
                $listener,
                $this->_events[$event],
                true
            );

            if ($key !== false) {

                array_splice(
                    $this->_events[$event],
                    $key,
                    1
                );
            }
        }

        return $this;
    }
601024
public function removeListener($event, $callback)
    {
        if (false === isset($this->listeners[$event])) {

            return;
        }

        $key = array_search($callback, $this->listeners[$event]);
        if ($key !== false) {
            unset($this->listeners[$event][$key]);

            if (0 === count($this->listeners[$event])) {
                unset($this->listeners[$event]);
            }
        }
    }
186925
public function listen($event, \Closure $callback): void
    {
        // check if $event is a single string and set it as array with one item
        if (!Any::isArray($event)) {
            $event = [$event];
        }
        
        // each every one event in array
        foreach ($event as $item) {
            if (Any::isArray($this->runned) && array_key_exists($item, $this->runned)) {
                call_user_func_array($callback, $this->runned[$item]);
            }
        }
    }
761575
public function subscribe(string $event, string $listener, callable $callback)
    {
        $callbackKey = $event . ' ' . $listener;
        $this->events[$event][] = $callbackKey;
        $this->subscriptions[$callbackKey] = $callback;
    }
1129905
protected function callListener($callable, Event $event)
    {
        if ($callable instanceof Closure || is_array($callable)) {
            call_user_func_array($callable, array_filter([$event, $event->getSubject(), $event->getData()]));
        } elseif (is_object($callable)) {
            $callable->{$event->getType()}($event, $event->getSubject(), $event->getData());
        }
    }
1072347
protected function removeListenerFromEvent(callable $listener, string $event) : interfaces\Emitter
    {
        foreach ($this->listeners[$event] as $priority => $listeners) {
            if (false !== $key = array_search($listener, $listeners, true)) {
                unset($this->listeners[$event][$priority][$key], $this->chain[$event]);
            }
        }

        return $this;
    }
930434
public function on($event, \Closure $callback): void
    {
        // check if event is a single string and parse it to array single item
        if (!Any::isArray($event)) {
            $event = [$event];
        }
        
        foreach ($event as $item) {
            $this->events[$item][] = $callback;
        }
    }
123184
public function attach($event, $callback) {
        $events = is_array($event) ? $event : array($event);
        $listeners = $this->getOption(self::OPTION_LISTENERS);
        foreach ($events as $event) {
            $eventObject = is_object($event) ? $event : new GenericEvent($event);
            if (!isset($listeners[$eventObject->getName()])) {
                $listeners[$eventObject->getName()] = array();
            }

            if (!in_array($callback, $listeners[$eventObject->getName()], true)) {
                $listeners[$eventObject->getName()][] = $callback;
            }
        }
        $this->setOption(self::OPTION_LISTENERS, $listeners);
    }
73915
public function unlisten($event = null, $listener = null)
    {
        // if event is null, remove all listeners
        if ($event=== null){
            $this->listeners = null;
            return;
        }
        // if listener parameter set null, all event specific listeners are removed
        if (!$listener){
            unset($this->listeners[$event]);
            return;
        }
        // get event specific listeners
        $listers_of_event = isset($this->listeners[$event]) ? $this->listeners[$event] : null;
        // remove all listeners
        if (is_array($listers_of_event)){
            while(($key=array_search($listener,$listers_of_event,true)) !== false){
                unset($listers_of_event[$key]);
                if (!empty($listers_of_event)){
                    // update listener holder, if listeners still exist
                    $this->listeners[$event] = $listers_of_event;
                }
                else{
                    // clean empty listener holder
                    unset($this->listeners[$event]);
                }
            }
        }
    }
804147
public static function listen(string $event, callable $callback) {
		if (!isset(self::$events[$event])) {
			self::$events[$event] = [];
		}
		self::$events[$event][] = $callback;
	}
1290850
public function killCallback($callback)
    {
        $key = $this->getCallbackKey($callback);

        self::$_baseRealCallbacks[$key] = false;

        return $this;
    }
963406
public function unregister($event, $callback = null)
	{
		if (isset($this->_events[$event]))
		{
			if ($callback === null)
			{
				unset($this->_events[$event]);
				return true;
			}

			foreach ($this->_events[$event] as $i => $arguments)
			{
				if($callback === $arguments[1])
				{
					unset($this->_events[$event][$i]);
					return true;
				}
			}
		}

		return false;
	}
451556
public function listen($event, $listener){
        if (!$this->emitter){
            return $this;
        }
        $this->emitter->listen($event, $listener);
        return $this;
    }