1 | <?php |
||
13 | class ResponseBuilder |
||
14 | { |
||
15 | /** |
||
16 | * Response content. |
||
17 | * |
||
18 | * @var mixed |
||
19 | */ |
||
20 | protected $response; |
||
21 | |||
22 | /** |
||
23 | * The HTTP response headers. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $headers = []; |
||
28 | |||
29 | /** |
||
30 | * The HTTP response cookies. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $cookies = []; |
||
35 | |||
36 | /** |
||
37 | * The HTTP response status code. |
||
38 | * |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $statusCode = 200; |
||
42 | |||
43 | /** |
||
44 | * Create a new response builder instance. |
||
45 | * |
||
46 | * @param mixed $response |
||
47 | */ |
||
48 | 20 | public function __construct($response) |
|
52 | |||
53 | /** |
||
54 | * Add a cookie to the response. |
||
55 | * |
||
56 | * @param \Symfony\Component\HttpFoundation\Cookie $cookie |
||
57 | * |
||
58 | * @return ResponseBuilder |
||
59 | */ |
||
60 | 4 | public function withCookie(Cookie $cookie) |
|
66 | |||
67 | /** |
||
68 | * Add a cookie to the response. |
||
69 | * |
||
70 | * @param \Symfony\Component\HttpFoundation\Cookie $cookie |
||
71 | * |
||
72 | * @return ResponseBuilder |
||
73 | */ |
||
74 | 2 | public function cookie(Cookie $cookie) |
|
78 | |||
79 | /** |
||
80 | * Add a header to the response. |
||
81 | * |
||
82 | * @param string $name |
||
83 | * @param string $value |
||
84 | * |
||
85 | * @return ResponseBuilder |
||
86 | */ |
||
87 | 3 | public function withHeader($name, $value) |
|
93 | |||
94 | /** |
||
95 | * Add a header to the response. |
||
96 | * |
||
97 | * @param string $name |
||
98 | * @param string $value |
||
99 | * |
||
100 | * @return ResponseBuilder |
||
101 | */ |
||
102 | 2 | public function header($name, $value) |
|
106 | |||
107 | /** |
||
108 | * Set the responses status code. |
||
109 | * |
||
110 | * @param int $statusCode |
||
111 | * |
||
112 | * @return ResponseBuilder |
||
113 | */ |
||
114 | 9 | public function setStatusCode($statusCode) |
|
120 | |||
121 | /** |
||
122 | * Set the response status code. |
||
123 | * |
||
124 | * @param int $statusCode |
||
125 | * |
||
126 | * @return ResponseBuilder |
||
127 | */ |
||
128 | 1 | public function statusCode($statusCode) |
|
132 | |||
133 | /** |
||
134 | * Build the response. |
||
135 | * |
||
136 | * @return \Illuminate\Http\Response |
||
137 | */ |
||
138 | 14 | public function build() |
|
153 | |||
154 | /** |
||
155 | * Returns cookies. |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | 3 | public function getCookies() |
|
163 | |||
164 | /** |
||
165 | * Return headers. |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | 2 | public function getHeaders() |
|
173 | |||
174 | /** |
||
175 | * Return status code. |
||
176 | * |
||
177 | * @return int |
||
178 | */ |
||
179 | 1 | public function getStatusCode() |
|
183 | |||
184 | /** |
||
185 | * Add meta to response |
||
186 | * |
||
187 | * @param $key |
||
188 | * @param $value |
||
189 | * @return $this |
||
190 | */ |
||
191 | public function setMeta($key, $value) |
||
201 | } |
||
202 |