Example #1
0
 /**
  * @covers Context::setRouter
  * @covers Context::getRouter
  */
 public function testSetRouter()
 {
     $factory = new RouterFactory();
     $router = $factory->newInstance();
     $actual = $this->ctx->getRouter();
     $this->assertNull($actual);
     $this->ctx->setRouter($router);
     $actual = $this->ctx->getRouter();
     $this->assertSame($router, $actual);
 }
Example #2
0
 /**
  * Use the router to generate a new URL to this website.
  * This allows generating a link using a 'routeName' rather than assuming that
  * you know the actual format of the path.
  *
  * @param String $routeName the routing name to use (as defined in routes.yaml)
  * @param Array $data data to use as variables for the route
  * @param Boolean $useCurrentParams if true, uses data from current route and
  *        then overrides with params given by the $data parameter.
  * @return Href
  */
 public function generateURL($routeName, $data = array(), $useCurrentParams = false)
 {
     $router = $this->ctx->getRouter();
     if ($useCurrentParams) {
         $route = $router->getMatchedRoute();
         $data = array_merge($route->params, $data);
     }
     $url = '/' . $router->generate($routeName, $data);
     return new Href($url);
 }