コード例 #1
0
ファイル: Enlighten.php プロジェクト: roydejong/Enlighten
 /**
  * Sets the router that should be used to handle routing and request resolution duties.
  *
  * @param Router $router
  */
 public function setRouter(Router $router)
 {
     $this->router = $router;
     $this->router->setContext($this->context);
     $this->context->registerInstance($router);
 }
コード例 #2
0
ファイル: RouterTest.php プロジェクト: roydejong/Enlighten
 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'));
 }