Listen to a specific event name.

@param string $event
@param callable $listener
437817
public function addListener(string $event, $listener)
    {
        if (!isset($this->listeners[$event])) {
            $this->listeners[$event] = [];
        }
        $this->listeners[$event][] = $listener;
    }
340862
public function it_should_call_listeners_for_their_events_in_correct_priority_order_when_event_is_triggered(
        MockListener $listener,
        Event $event
    ) {
        $event->hasBeenHandled()
              ->willReturn(\false);
        $this->addListener('test1', [$listener, 'method1']);
        $this->addListener('test1', [$listener, 'method2']);
        $this->addListener('test1', [$listener, 'method1'], 'first');
        $this->addListener('test1', [$listener, 'method1'], 'last');
        $this->getListeners()
             ->shouldHaveKey('test1');
        $listener->method1($event, 'test1', $this)
                 ->shouldBeCalled();
        $listener->method1($event, 'test1', $this)
                 ->willReturn($event);
        $listener->method2($event, 'test1', $this)
                 ->shouldBeCalled();
        $listener->method2($event, 'test1', $this)
                 ->willReturn($event);
        $this->trigger('test1', $event);
        $expected = [
            1 => [[$listener, 'method1']],
            0 => [[$listener, 'method1'], [$listener, 'method2']],
            -1 => [[$listener, 'method1']]
        ];
        $this->getListeners('test1')
             ->shouldReturn($expected);
    }
650702
public function addEventListener(string $name, callable $listener): self
    {
        if (!isset($this->internalEventListenersData[$name])) {
            $this->internalEventListenersData[$name] = [];
        }
        $this->internalEventListenersData[$name][] = $listener;
        return $this;
    }
1172525
public function addListenerForEvent($eventClassName, $listener)
    {
        if (FALSE === array_key_exists($eventClassName, $this->eventMap))
        {
            $this->eventMap[$eventClassName] = [];
        }
        $this->eventMap[$eventClassName][] = $listener;
    }
710990
protected function makeListeners($event, $listeners)
    {
        foreach ($listeners as $listener) {
            $listener = preg_replace('/@.+$/', '', $listener);

            $this->call('generate:listener', ['name' => $listener, '--event' => $event]);
        }
    }
1350188
public function addEventListener(callable $listener): void
    {
        /** @var \Jasny\EventDispatcher\EventDispatcher $dispatcher */
        $dispatcher = type_check(
            $this->getEventDispatcher(),
            'Jasny\EventDispatcher\EventDispatcher',
            new LogicException('Unsupported event dispatcher. Please overload the addEventListener method.')
        );

        /** @var \Jasny\EventDispatcher\ListenerProvider $provider */
        $provider = type_check(
            $dispatcher->getListenerProvider(),
            'Jasny\EventDispatcher\ListenerProvider',
            new UnexpectedValueException('Unsupported listener provider; expected %2s, got %1s')
        );

        $newProvider = $provider->withListener($listener);
        $newDispatcher = $dispatcher->withListenerProvider($newProvider);

        $this->setEventDispatcher($newDispatcher);
    }
759023
public function addEventListener($eventName, $listener, $priority = EventPriority::NORMAL) {
        if (!isset($this->_listeners[$eventName][$priority])) {
            $this->_listeners->extendDeepValue(array($priority=>array()), $eventName);
        }
        $this->_listeners[$eventName][$priority][] = $listener;
    }
1342966
public function listen( Listener $listener ) {

		if ( isset( $this->listeners[ $listener->get_tag() ] ) ) {
			return false;
		}

		$this->listeners[ $listener->get_tag() ] = $listener;

		return true;
	}
755183
protected function callListener(callable $listener, array $args = [])
    {
        switch (count($args)) {
            case 0:
                return call_user_func($listener);
            case 1:
                return call_user_func($listener, $args[0]);
            case 2:
                return call_user_func($listener, $args[0], $args[1]);
            case 3:
                return call_user_func($listener, $args[0], $args[1], $args[2]);
            case 4:
                return call_user_func($listener, $args[0], $args[1], $args[2], $args[3]);
        }

        return call_user_func_array($listener, $args);
    }
1200418
public function on($event, callable $listener)
    {
        if ($this->markFilters) {
            $listener = $this->wrap($listener, '*', $this->markFilters);
        }

        $this->root->on($event, $listener);

        return $this;
    }
397742
public function listen($events, $listener, $priority=0)
    {

        if (!is_callable($listener)) {
            throw new InvalidArgumentException('Listener has to be callable');
        }

        foreach ((array)$events as $event) {

            if ($this->isWildcardSyntax($event)){
                $this->addWildCardListener($event, $listener, $priority);
            }
            $this->addListener($event, $listener, $priority);

        }
    }
1164308
public function onAfter($event, callable $listener)
    {

        if (strpos($event, '*') !== false) {
            $this->afterAnyListeners[] = $this->toWildcardListener($event, $listener);
            return $this;
        }

        self::parentOnAfter($event, $listener);

        return $this;
    }
761575
public function subscribe(string $event, string $listener, callable $callback)
    {
        $callbackKey = $event . ' ' . $listener;
        $this->events[$event][] = $callbackKey;
        $this->subscriptions[$callbackKey] = $callback;
    }
103215
public static function addListener($name, $listener)
    {
        if (!isset(static::$listeners[$name])) {
            static::$listeners[$name] = [];
        }

        static::$listeners[$name][] = $listener;
    }
1214073
public function onAfter($event, callable $listener)
    {
        if ($this->markFilters) {
            $listener = $this->wrap($listener, '*', $this->markFilters);
        }

        $this->root->onAfter($event, $listener);

        return $this;

    }
1108104
public function on($event, callable $listener)
    {
        if (is_object($event) || strpos($event, '\\')) { // looks like a class
            throw new UnsupportedParameterException('Only string based events are supported');
        }

        if (!isset($this->listeners[$event])) {
            $this->listeners[$event] = [];
        }
        $this->listeners[$event][] = $listener;

        return $this;
    }
1092993
public function subscribe($event, $listener, $priority = ListenerAcceptorInterface::P_NORMAL)
    {
        $this->addListener($event, $listener, $priority);
    }