Prooph\ServiceBus\Plugin\Router\RegexRouter::to PHP Метод

to() публичный Метод

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

Usage Example

Пример #1
0
 /**
  * @test
  * @expectedException \Prooph\ServiceBus\Exception\InvalidArgumentException
  */
 public function it_fails_when_routing_to_invalid_handler()
 {
     $router = new RegexRouter();
     $router->to(null);
 }