1 | <?php |
||
2 | |||
3 | // +---------------------------------------------------------------------- |
||
4 | // | ThinkLibrary 6.0 for ThinkPhP 6.0 |
||
5 | // +---------------------------------------------------------------------- |
||
6 | // | 版权所有 2017~2020 [ https://www.dtapp.net ] |
||
7 | // +---------------------------------------------------------------------- |
||
8 | // | 官方网站: https://gitee.com/liguangchun/ThinkLibrary |
||
9 | // +---------------------------------------------------------------------- |
||
10 | // | 开源协议 ( https://mit-license.org ) |
||
11 | // +---------------------------------------------------------------------- |
||
12 | // | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary |
||
13 | // | github 仓库地址 :https://github.com/GC0202/ThinkLibrary |
||
14 | // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
||
15 | // +---------------------------------------------------------------------- |
||
16 | |||
17 | namespace DtApp\ThinkLibrary\service; |
||
18 | |||
19 | use DtApp\ThinkLibrary\Service; |
||
20 | |||
21 | /** |
||
22 | * 路由服务 |
||
23 | * Class RouteService |
||
24 | * @package DtApp\ThinkLibrary\service |
||
25 | */ |
||
26 | class RouteService extends Service |
||
27 | { |
||
28 | /** |
||
29 | * 跳转到某地址 |
||
30 | * @param string $url |
||
31 | * @param int $status |
||
32 | * @param bool $parameter |
||
33 | */ |
||
34 | public function redirect(string $url = '', int $status = 302, bool $parameter = false): void |
||
35 | { |
||
36 | if (empty($url)) { |
||
37 | $url = request()->scheme() . "://" . request()->host(); |
||
38 | } |
||
39 | $param = http_build_query(request()->param()); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
40 | if ($status === 301) { |
||
41 | header('HTTP/1.1 301 Moved Permanently'); |
||
42 | } |
||
43 | if (empty($parameter)) { |
||
44 | header("Location: {$url}"); |
||
45 | } elseif (empty($parameter) === false && empty($param) === true) { |
||
46 | header("Location: {$url}"); |
||
47 | } else { |
||
48 | header("Location: {$url}?{$param}"); |
||
49 | } |
||
50 | exit; |
||
0 ignored issues
–
show
|
|||
51 | } |
||
52 | } |
||
53 |