Prooph\ServiceBus\Plugin\Router\EventRouter::to PHP Méthode

to() public méthode

public to ( string | object | callable $eventListener )
$eventListener string | object | callable
    public function to($eventListener)
    {
        if (!is_string($eventListener) && !is_object($eventListener) && !is_callable($eventListener)) {
            throw new Exception\InvalidArgumentException(sprintf("Invalid event listener provided. Expected type is string, object or callable but type of %s given.", gettype($eventListener)));
        }
        if (null === $this->tmpEventName) {
            throw new Exception\RuntimeException(sprintf("Cannot map listener %s to an event. Please use method route before calling method to", is_object($eventListener) ? get_class($eventListener) : is_string($eventListener) ? $eventListener : gettype($eventListener)));
        }
        $this->eventMap[$this->tmpEventName][] = $eventListener;
        return $this;
    }

Usage Example

 /**
  * @test
  * @expectedException \Prooph\ServiceBus\Exception\InvalidArgumentException
  */
 public function it_fails_on_setting_an_invalid_listener()
 {
     $router = new EventRouter();
     $router->to(null);
 }