1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Bluz Framework Component |
5
|
|
|
* |
6
|
|
|
* @copyright Bluz PHP Team |
7
|
|
|
* @link https://github.com/bluzphp/framework |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Bluz\Proxy; |
13
|
|
|
|
14
|
|
|
use Bluz\Common\Exception\ComponentException; |
15
|
|
|
use Bluz\Controller\Controller; |
16
|
|
|
use Bluz\Http\Exception\RedirectException; |
17
|
|
|
use Bluz\Response\Response as Instance; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Proxy to Response |
21
|
|
|
* |
22
|
|
|
* Example of usage |
23
|
|
|
* <code> |
24
|
|
|
* use Bluz\Proxy\Response; |
25
|
|
|
* |
26
|
|
|
* Response::setStatusCode(304); |
27
|
|
|
* Response::setHeader('Location', '/index/index'); |
28
|
|
|
* </code> |
29
|
|
|
* |
30
|
|
|
* @package Bluz\Proxy |
31
|
|
|
* @author Anton Shevchuk |
32
|
|
|
* |
33
|
|
|
* @method static Instance getInstance() |
34
|
|
|
* |
35
|
|
|
* @method static string getProtocolVersion() |
36
|
|
|
* @see Instance::getProtocolVersion() |
37
|
|
|
* |
38
|
|
|
* @method static string getStatusCode() |
39
|
|
|
* @see Instance::getStatusCode() |
40
|
|
|
* @method static void setStatusCode($code) |
41
|
|
|
* @see Instance::setStatusCode() |
42
|
|
|
* |
43
|
|
|
* @method static void setReasonPhrase($phrase) |
44
|
|
|
* @see Instance::setReasonPhrase() |
45
|
|
|
* @method static string getReasonPhrase() |
46
|
|
|
* @see Instance::getReasonPhrase() |
47
|
|
|
* |
48
|
|
|
* @method static string getHeader($header) |
49
|
|
|
* @see Instance::getHeader() |
50
|
|
|
* @method static array getHeaderAsArray($header) |
51
|
|
|
* @see Instance::getHeaderAsArray() |
52
|
|
|
* @method static bool hasHeader($header) |
53
|
|
|
* @see Instance::hasHeader() |
54
|
|
|
* @method static void setHeader($header, $value) |
55
|
|
|
* @see Instance::setHeader() |
56
|
|
|
* @method static void addHeader($header, $value) |
57
|
|
|
* @see Instance::addHeader() |
58
|
|
|
* @method static void removeHeader($header) |
59
|
|
|
* @see Instance::removeHeader() |
60
|
|
|
* |
61
|
|
|
* @method static array getHeaders() |
62
|
|
|
* @see Instance::getHeaders() |
63
|
|
|
* @method static void setHeaders(array $headers) |
64
|
|
|
* @see Instance::setHeaders() |
65
|
|
|
* @method static void addHeaders(array $headers) |
66
|
|
|
* @see Instance::addHeaders() |
67
|
|
|
* @method static void removeHeaders() |
68
|
|
|
* @see Instance::removeHeaders() |
69
|
|
|
* |
70
|
|
|
* @method static void setBody($phrase) |
71
|
|
|
* @see Instance::setBody() |
72
|
|
|
* @method static Controller getBody() |
73
|
|
|
* @see Instance::getBody() |
74
|
|
|
* @method static void clearBody() |
75
|
|
|
* @see Instance::clearBody() |
76
|
|
|
* |
77
|
|
|
* @method static void setCookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $s = null, $h = null) |
78
|
|
|
* @see Instance::setCookie() |
79
|
|
|
* @method static array getCookie() |
80
|
|
|
* @see Instance::getCookie() |
81
|
|
|
* |
82
|
|
|
* @method static string getType() |
83
|
|
|
* @see Instance::getType() |
84
|
|
|
* @method static void setType($type) |
85
|
|
|
* @see Instance::setType() |
86
|
|
|
* |
87
|
|
|
* @method static void send() |
88
|
|
|
* @see Instance::send() |
89
|
|
|
*/ |
90
|
|
|
final class Response |
91
|
|
|
{ |
92
|
|
|
use ProxyTrait; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Init instance |
96
|
|
|
* |
97
|
|
|
* @throws ComponentException |
98
|
|
|
*/ |
99
|
|
|
private static function initInstance() |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
throw new ComponentException("Class `Proxy\\Request` required external initialization"); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Redirect to URL |
106
|
|
|
* |
107
|
|
|
* @param string $url |
108
|
|
|
* |
109
|
|
|
* @return void |
110
|
|
|
* @throws RedirectException |
111
|
|
|
*/ |
112
|
5 |
|
public static function redirect($url): void |
113
|
|
|
{ |
114
|
5 |
|
$redirect = new RedirectException(); |
115
|
5 |
|
$redirect->setUrl($url); |
116
|
5 |
|
throw $redirect; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Redirect to controller |
121
|
|
|
* |
122
|
|
|
* @param string $module |
123
|
|
|
* @param string $controller |
124
|
|
|
* @param array $params |
125
|
|
|
* |
126
|
|
|
* @return void |
127
|
|
|
* @throws RedirectException |
128
|
|
|
*/ |
129
|
3 |
|
public static function redirectTo($module, $controller = 'index', array $params = []): void |
130
|
|
|
{ |
131
|
3 |
|
$url = Router::getFullUrl($module, $controller, $params); |
132
|
3 |
|
self::redirect($url); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Reload current page please, be careful to avoid loop of reload |
137
|
|
|
* |
138
|
|
|
* @return void |
139
|
|
|
* @throws RedirectException |
140
|
|
|
*/ |
141
|
1 |
|
public static function reload(): void |
142
|
|
|
{ |
143
|
1 |
|
self::redirect((string) Request::getUri()); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.