-
-
Notifications
You must be signed in to change notification settings - Fork 828
/
Action.php
62 lines (53 loc) · 1.37 KB
/
Action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Support;
use Psr\Http\Message\ServerRequestInterface as Request;
use Zend\Diactoros\Response\EmptyResponse;
use Zend\Diactoros\Response\RedirectResponse;
use Flarum\Core;
abstract class Action
{
/**
* @param Request $request
* @param array $routeParams
* @return \Psr\Http\Message\ResponseInterface
*/
abstract public function handle(Request $request, array $routeParams = []);
/**
* @return EmptyResponse
*/
protected function success()
{
return new EmptyResponse();
}
/**
* @param string $url
* @return RedirectResponse
*/
protected function redirectTo($url)
{
$url = Core::url() . $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'));
$response = new RedirectResponse($url);
$response->getBody()->write($content);
return $response;
}
}