Implement helper method for redirecting

This commit is contained in:
Franz Liedke 2015-05-27 02:48:08 +02:00
parent 69038857fa
commit fd2ee008fa

View File

@ -1,7 +1,8 @@
<?php namespace Flarum\Support;
use Illuminate\Http\Request;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ServerRequestInterface as Request;
use Zend\Diactoros\Response;
abstract class Action
{
@ -18,4 +19,26 @@ abstract class Action
$action = app($class);
return $action->call($params);
}
/**
* @param string $url
* @return \Psr\Http\Message\ResponseInterface
*/
protected function redirectTo($url)
{
$content = sprintf('<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="1;url=%1$s" />
<title>Redirecting to %1$s</title>
</head>
<body>
Redirecting to <a href="%1$s">%1$s</a>.
</body>
</html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8'));
return new Response($content, 302, ['location' => $url]);
}
}