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 | 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 | 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 | 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 | 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 | public function header($name, $value) |
||
106 | |||
107 | /** |
||
108 | * Set the responses status code. |
||
109 | * |
||
110 | * @param int $statusCode |
||
111 | * |
||
112 | * @return ResponseBuilder |
||
113 | */ |
||
114 | public function setStatusCode($statusCode) |
||
120 | |||
121 | /** |
||
122 | * Set the response status code. |
||
123 | * |
||
124 | * @param int $statusCode |
||
125 | * |
||
126 | * @return ResponseBuilder |
||
127 | */ |
||
128 | public function statusCode($statusCode) |
||
132 | |||
133 | /** |
||
134 | * Build the response. |
||
135 | * |
||
136 | * @return \Illuminate\Http\Response |
||
137 | */ |
||
138 | public function build() |
||
150 | |||
151 | /** |
||
152 | * Returns cookies. |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | public function getCookies() |
||
160 | |||
161 | /** |
||
162 | * Return headers. |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | public function getHeaders() |
||
170 | |||
171 | /** |
||
172 | * Return status code. |
||
173 | * |
||
174 | * @return int |
||
175 | */ |
||
176 | public function getStatusCode() |
||
180 | } |
||
181 |