/** * @param Topic $topic * @param string|null $tokenSeparator * * @return WampRequest * * @throws ResourceNotFoundException * @throws \Exception */ public function match(Topic $topic, $tokenSeparator = null) { try { list($routeName, $route, $attributes) = $this->pubSubRouter->match($topic->getId(), $tokenSeparator); if ($this->debug) { $this->logger->debug(sprintf('Matched route "%s"', $routeName), $attributes); } return new WampRequest($routeName, $route, new ParameterBag($attributes), $topic->getId()); } catch (ResourceNotFoundException $e) { $this->logger->error(sprintf('Unable to find route for %s', $topic->getId())); throw $e; } }
public function testMatchWithoutContext() { //without context $routeCollection = $this->prophesize(RouteCollection::CLASS); $matcher = $this->prophesize(Matcher::CLASS); $routeLoader = $this->prophesize(RouteLoader::CLASS); $generator = $this->prophesize(Generator::CLASS); $matcher->match('foo', '/')->shouldBeCalled(); $router = new Router($routeCollection->reveal(), $matcher->reveal(), $generator->reveal(), $routeLoader->reveal()); $router->match('foo', '/'); //with context $matcher = $this->prophesize(Matcher::CLASS); $matcher->match('foo', '/')->shouldBeCalled(); $router = new Router($routeCollection->reveal(), $matcher->reveal(), $generator->reveal(), $routeLoader->reveal()); $context = $this->prophesize(RouterContext::CLASS); $context->getTokenSeparator()->willReturn('/'); $router->setContext($context->reveal()); $router->match('foo'); //with context overriding $matcher = $this->prophesize(Matcher::CLASS); $matcher->match('foo', ':')->shouldBeCalled(); $router = new Router($routeCollection->reveal(), $matcher->reveal(), $generator->reveal(), $routeLoader->reveal()); $context = $this->prophesize(RouterContext::CLASS); $context->getTokenSeparator()->willReturn('/'); $router->setContext($context->reveal()); $router->match('foo', ':'); }