24
24
*/
25
25
class ResponseBuilder extends ResponseBuilderBase
26
26
{
27
-
28
27
/** @var bool */
29
28
protected $ success = false ;
30
29
@@ -123,13 +122,23 @@ public static function error(int $api_code, array $placeholders = null, $data =
123
122
->build ();
124
123
}
125
124
126
- // -----------------------------------------------------------------------------------------------------------
125
+ // -----------------------------------------------------------------------------------------------------------
127
126
127
+ /**
128
+ * @param int|null $api_code
129
+ *
130
+ * @return \MarcinOrlowski\ResponseBuilder\ResponseBuilder
131
+ */
128
132
public static function asSuccess (int $ api_code = null ): self
129
133
{
130
134
return new self (true , $ api_code ?? BaseApiCodes::OK ());
131
135
}
132
136
137
+ /**
138
+ * @param int $api_code
139
+ *
140
+ * @return \MarcinOrlowski\ResponseBuilder\ResponseBuilder
141
+ */
133
142
public static function asError (int $ api_code ): self
134
143
{
135
144
$ code_ok = BaseApiCodes::OK ();
@@ -144,6 +153,11 @@ public static function asError(int $api_code): self
144
153
return new self (false , $ api_code );
145
154
}
146
155
156
+ /**
157
+ * @param int|null $http_code
158
+ *
159
+ * @return $this
160
+ */
147
161
public function withHttpCode (int $ http_code = null ): self
148
162
{
149
163
Validator::assertIsType ('http_code ' , $ http_code , [Validator::TYPE_INTEGER ,
@@ -153,6 +167,11 @@ public function withHttpCode(int $http_code = null): self
153
167
return $ this ;
154
168
}
155
169
170
+ /**
171
+ * @param null $data
172
+ *
173
+ * @return $this
174
+ */
156
175
public function withData ($ data = null ): self
157
176
{
158
177
Validator::assertIsType ('data ' , $ data , [Validator::TYPE_ARRAY ,
@@ -163,6 +182,11 @@ public function withData($data = null): self
163
182
return $ this ;
164
183
}
165
184
185
+ /**
186
+ * @param int|null $json_opts
187
+ *
188
+ * @return $this
189
+ */
166
190
public function withJsonOptions (int $ json_opts = null ): self
167
191
{
168
192
Validator::assertIsType ('json_opts ' , $ json_opts , [Validator::TYPE_INTEGER ,
@@ -172,6 +196,11 @@ public function withJsonOptions(int $json_opts = null): self
172
196
return $ this ;
173
197
}
174
198
199
+ /**
200
+ * @param array|null $debug_data
201
+ *
202
+ * @return $this
203
+ */
175
204
public function withDebugData (array $ debug_data = null ): self
176
205
{
177
206
Validator::assertIsType ('$debug_data ' , $ debug_data , [Validator::TYPE_ARRAY ,
@@ -181,6 +210,11 @@ public function withDebugData(array $debug_data = null): self
181
210
return $ this ;
182
211
}
183
212
213
+ /**
214
+ * @param string|null $msg
215
+ *
216
+ * @return $this
217
+ */
184
218
public function withMessage (string $ msg = null ): self
185
219
{
186
220
Validator::assertIsType ('message ' , $ msg , [Validator::TYPE_STRING ,
@@ -190,20 +224,37 @@ public function withMessage(string $msg = null): self
190
224
return $ this ;
191
225
}
192
226
227
+ /**
228
+ * @param array|null $placeholders
229
+ *
230
+ * @return $this
231
+ */
193
232
public function withPlaceholders (array $ placeholders = null ): self
194
233
{
195
234
$ this ->placeholders = $ placeholders ;
196
235
197
236
return $ this ;
198
237
}
199
238
239
+ /**
240
+ * @param array|null $http_headers
241
+ *
242
+ * @return $this
243
+ */
200
244
public function withHttpHeaders (array $ http_headers = null ): self
201
245
{
202
246
$ this ->http_headers = $ http_headers ?? [];
203
247
204
248
return $ this ;
205
249
}
206
250
251
+ /**
252
+ * Builds and returns final HttpResponse. It's safe to call build() as many times as needed, as no
253
+ * internal state is changed. It's also safe to alter any parameter set previously and call build()
254
+ * again to get new response object that includes new changes.
255
+ *
256
+ * @return \Symfony\Component\HttpFoundation\Response
257
+ */
207
258
public function build (): HttpResponse
208
259
{
209
260
$ api_code = $ this ->api_code ;
0 commit comments