Commit f674b3be authored by Fabien Potencier's avatar Fabien Potencier

merged igows/redirect

parents 12bb71b2 8cc98bdc
...@@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; ...@@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Events as HttpKernelEvents; use Symfony\Component\HttpKernel\Events as HttpKernelEvents;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
...@@ -242,6 +243,19 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -242,6 +243,19 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this['controllers']->flush(); $this['controllers']->flush();
} }
/**
* Redirects the user to another URL.
*
* @param string $url The URL to redirect to
* @param integer $status The status code (302 by default)
*
* @see Symfony\Component\HttpFoundation\RedirectResponse
*/
public function redirect($url, $status = 302)
{
return new RedirectResponse($url, $status);
}
/** /**
* Handles the request and deliver the response. * Handles the request and deliver the response.
* *
......
...@@ -83,9 +83,17 @@ class RouterTest extends \PHPUnit_Framework_TestCase ...@@ -83,9 +83,17 @@ class RouterTest extends \PHPUnit_Framework_TestCase
return new RedirectResponse('/target'); return new RedirectResponse('/target');
}); });
$application->match('/redirect2', function() use ($application) {
return $application->redirect('/target2');
});
$request = Request::create('/redirect'); $request = Request::create('/redirect');
$response = $application->handle($request); $response = $application->handle($request);
$this->assertTrue($response->isRedirected('/target')); $this->assertTrue($response->isRedirected('/target'));
$request = Request::create('/redirect2');
$response = $application->handle($request);
$this->assertTrue($response->isRedirected('/target2'));
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment