Exemple #1
0
 /**
  * Registers a new redirection route.
  *
  * @param string $from The route mask to match against. Can optionally contain variable components, but they are used for matching only.
  * @param string $to The static URL to redirect the user to.
  * @param bool $permanent If true, a HTTP 301 permanent redirect is used. Otherwise, a HTTP 302 temporary redirect is used (default).
  * @return Route The generated route.
  */
 public function redirect($from, $to, $permanent = false)
 {
     $this->bootstrapRouter();
     return $this->router->createRedirect($from, $to, $permanent);
 }
Exemple #2
0
 public function testCreateRedirect()
 {
     // Prepare: Prepare environment to capture response
     $response = new Response();
     $request = new Request();
     $request->setRequestUri('/redirect/bla');
     $context = new Context();
     $context->registerInstance($response);
     $context->registerInstance($request);
     $router = new Router();
     $router->setContext($context);
     $route = $router->createRedirect('/redirect/$testVar', '/target/$testVar', true);
     $this->assertEquals('/redirect/$testVar', $route->getPattern());
     $routeResult = $router->route($request);
     $this->assertEquals($route, $routeResult);
     $router->dispatch($routeResult, $request);
     $this->assertEquals(ResponseCode::HTTP_MOVED_PERMANENTLY, $response->getResponseCode());
     $this->assertEquals('/target/bla', $response->getHeader('Location'));
 }