Commit 8cc98bdc authored by Igor Wiedler's avatar Igor Wiedler

Application::redirect convenience method

parent 5aa6a974
......@@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -233,6 +234,19 @@ class Application extends HttpKernel implements EventSubscriberInterface
$this->controllers->flush();
}
/**
* Redirect
*
* @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);
}
/**
* Handle the request and deliver the response.
*
......
......@@ -83,9 +83,17 @@ class RouterTest extends \PHPUnit_Framework_TestCase
return new RedirectResponse('/target');
});
$application->match('/redirect2', function() use ($application) {
return $application->redirect('/target2');
});
$request = Request::create('/redirect');
$response = $application->handle($request);
$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