1 | <?php |
||
10 | class Response { |
||
11 | use |
||
12 | Singleton; |
||
13 | /** |
||
14 | * Protocol, for instance: `HTTP/1.0`, `HTTP/1.1` (default), HTTP/2.0 |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | public $protocol; |
||
19 | /** |
||
20 | * HTTP status code |
||
21 | * |
||
22 | * @var int |
||
23 | */ |
||
24 | public $code; |
||
25 | /** |
||
26 | * Headers are normalized to lowercase keys with hyphen as separator, for instance: `connection`, `referer`, `content-type`, `accept-language` |
||
27 | * |
||
28 | * Values might be strings in case of single value or array of strings in case of multiple values with the same field name |
||
29 | * |
||
30 | * @var string[]|string[][] |
||
31 | */ |
||
32 | public $headers; |
||
33 | /** |
||
34 | * String body (is used instead of `$this->body_stream` in most cases) |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | public $body; |
||
39 | /** |
||
40 | * Body in form of stream (might be used instead of `$this->body` in some cases, if present, `$this->body` is ignored) |
||
41 | * |
||
42 | * Stream is read/write |
||
43 | * |
||
44 | * @var resource |
||
45 | */ |
||
46 | public $body_stream; |
||
47 | /** |
||
48 | * Initialize response object with specified data |
||
49 | * |
||
50 | * @param string $body |
||
51 | * @param null|resource|string $body_stream String, like `php://temp` or resource, like `fopen('php://temp', 'ba+')`, if present, `$body` is ignored |
||
52 | * @param string[]|string[][] $headers Headers are normalized to lowercase keys with hyphen as separator, for instance: `connection`, `referer`, |
||
53 | * `content-type`, `accept-language`; Values might be strings in case of single value or array of strings in case |
||
54 | * of multiple values with the same field name |
||
55 | * @param int $code HTTP status code |
||
56 | * @param string $protocol Protocol, for instance: `HTTP/1.0`, `HTTP/1.1` (default), HTTP/2.0 |
||
57 | * |
||
58 | * @return Response |
||
59 | */ |
||
60 | function init ($body = '', $body_stream = null, $headers = [], $code = 200, $protocol = 'HTTP/1.1') { |
||
71 | /** |
||
72 | * Set raw HTTP header |
||
73 | * |
||
74 | * @param string $field Field |
||
75 | * @param string $value Value, empty string will cause header removal |
||
76 | * @param bool $replace The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header |
||
77 | * of the same type. By default it will replace |
||
78 | * |
||
79 | * @return Response |
||
80 | */ |
||
81 | function header ($field, $value, $replace = true) { |
||
92 | /** |
||
93 | * Make redirect to specified location |
||
94 | * |
||
95 | * @param string $location |
||
96 | * @param int|null $code |
||
|
|||
97 | * |
||
98 | * @return Response |
||
99 | */ |
||
100 | function redirect ($location, $code = 302) { |
||
105 | /** |
||
106 | * Function for setting cookies, taking into account cookies prefix. Parameters like in system `setcookie()` function, but $path, $domain and $secure |
||
107 | * are skipped, they are detected automatically |
||
108 | * |
||
109 | * This function have side effect of setting cookie on `cs\Request` object |
||
110 | * |
||
111 | * @param string $name |
||
112 | * @param string $value |
||
113 | * @param int $expire |
||
114 | * @param bool $httponly |
||
115 | * |
||
116 | * @return Response |
||
117 | */ |
||
118 | function cookie ($name, $value, $expire = 0, $httponly = false) { |
||
156 | /** |
||
157 | * Provides standard output for all the response data |
||
158 | */ |
||
159 | function standard_output () { |
||
175 | } |
||
176 |