src/Valkyrja/Events/NativeEvents.php
public function listen(string $event, Listener $listener): void
    {
        $this->add($event);

        $this->app->dispatcher()->verifyDispatch($listener);

        // If this listener has an id
        if (null !== $listener->getId()) {
            // Use it when setting to allow removal
            // or checking if it exists later
            self::$events[$event][$listener->getId()] = $listener;
        } else {
            // Otherwise set the listener normally
            self::$events[$event][] = $listener;
        }
    }
public function listen(string $event, Listener $listener): void
    {
        $this->add($event);

        $this->app->dispatcher()->verifyDispatch($listener);

        // If this listener has an id
        if (null !== $listener->getId()) {
            // Use it when setting to allow removal
            // or checking if it exists later
            self::$events[$event][$listener->getId()] = $listener;
        } else {
            // Otherwise set the listener normally
            self::$events[$event][] = $listener;
        }
    }
Add an event listener.

@param string   $event    The event
@param Listener $listener The event listener

@throws \Valkyrja\Dispatcher\Exceptions\InvalidClosureException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidDispatchCapabilityException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidFunctionException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidMethodException
@throws \Valkyrja\Dispatcher\Exceptions\InvalidPropertyException

@return void