25
25
*/
26
26
class ResponseBuilder extends ResponseBuilderBase
27
27
{
28
- protected bool $ success = false ;
28
+ protected bool $ success = false ;
29
29
protected int $ api_code ;
30
- protected ?int $ http_code = null ;
31
- protected ?string $ message = null ;
30
+ protected ?int $ http_code = null ;
31
+ protected ?string $ message = null ;
32
32
/** @var array<string, mixed>|null */
33
- protected ?array $ placeholders = null ;
34
- protected ?int $ json_opts = null ;
33
+ protected ?array $ placeholders = null ;
34
+ protected ?int $ json_opts = null ;
35
35
/** @var array<string, mixed>|null */
36
- protected ?array $ debug_data = null ;
36
+ protected ?array $ debug_data = null ;
37
37
/** @var array<string, mixed> */
38
- protected array $ http_headers = [];
38
+ protected array $ http_headers = [];
39
39
40
40
/** @var mixed|null $data */
41
41
protected $ data = null ;
@@ -59,18 +59,18 @@ protected function __construct(bool $success, int $api_code)
59
59
/**
60
60
* Returns success
61
61
*
62
- * @param mixed|null $data Array of primitives and supported objects to be returned in
63
- * 'data' node of the JSON response, single supported object
64
- * or @null if there's no to be returned.
65
- * @param integer|null $api_code API code to be returned or @null to use value of
66
- * BaseApiCodes::OK().
67
- * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message placeholders
68
- * substitution or @null if none.
69
- * @param integer|null $http_code HTTP code to be used for HttpResponse sent or @null
70
- * for default DEFAULT_HTTP_CODE_OK.
71
- * @param integer|null $json_opts See http://php.net/manual/en/function.json-encode.php for
72
- * supported options or pass @null to use value from your
73
- * config (or defaults).
62
+ * @param mixed|null $data Array of primitives and supported objects to be returned in
63
+ * 'data' node of the JSON response, single supported object
64
+ * or @null if there's no to be returned.
65
+ * @param integer|null $api_code API code to be returned or @null to use value of
66
+ * BaseApiCodes::OK().
67
+ * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message placeholders
68
+ * substitution or @null if none.
69
+ * @param integer|null $http_code HTTP code to be used for HttpResponse sent or @null
70
+ * for default DEFAULT_HTTP_CODE_OK.
71
+ * @param integer|null $json_opts See http://php.net/manual/en/function.json-encode.php for
72
+ * supported options or pass @null to use value from your
73
+ * config (or defaults).
74
74
*
75
75
* @throws Ex\MissingConfigurationKeyException
76
76
* @throws Ex\ConfigurationNotFoundException
@@ -97,17 +97,17 @@ public static function success(mixed $data = null,
97
97
* Builds error Response object. Supports optional arguments passed to Lang::get() if associated error
98
98
* message uses placeholders as well as return data payload
99
99
*
100
- * @param integer $api_code Your API code to be returned with the response object.
101
- * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message
102
- * placeholders substitution or @null if none.
103
- * @param object|array<string, mixed>|null $data Array of primitives and supported objects to be
104
- * returned in 'data' node of the JSON response, single
105
- * supported object or @null if there's no to be returned.
106
- * @param integer|null $http_code HTTP code to be used for HttpResponse sent or @null
107
- * for default DEFAULT_HTTP_CODE_ERROR.
108
- * @param integer|null $json_opts See http://php.net/manual/en/function.json-encode.php
109
- * for supported options or pass @null to use value from
110
- * your config (or defaults).
100
+ * @param integer $api_code Your API code to be returned with the response object.
101
+ * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message
102
+ * placeholders substitution or @null if none.
103
+ * @param object|array<string, mixed>|null $data Array of primitives and supported objects to be
104
+ * returned in 'data' node of the JSON response, single
105
+ * supported object or @null if there's no to be returned.
106
+ * @param integer|null $http_code HTTP code to be used for HttpResponse sent or @null
107
+ * for default DEFAULT_HTTP_CODE_ERROR.
108
+ * @param integer|null $json_opts See http://php.net/manual/en/function.json-encode.php
109
+ * for supported options or pass @null to use value from
110
+ * your config (or defaults).
111
111
*
112
112
* @throws Ex\ArrayWithMixedKeysException
113
113
* @throws Ex\MissingConfigurationKeyException
@@ -119,8 +119,8 @@ public static function success(mixed $data = null,
119
119
public static function error (int $ api_code ,
120
120
?array $ placeholders = null ,
121
121
mixed $ data = null ,
122
- int $ http_code = null ,
123
- int $ json_opts = null ): HttpResponse
122
+ ? int $ http_code = null ,
123
+ ? int $ json_opts = null ): HttpResponse
124
124
{
125
125
return static ::asError ($ api_code )
126
126
->withPlaceholders ($ placeholders )
@@ -139,7 +139,7 @@ public static function error(int $api_code,
139
139
* @throws Ex\MissingConfigurationKeyException
140
140
* @throws Ex\NotIntegerException
141
141
*/
142
- public static function asSuccess (int $ api_code = null ): self
142
+ public static function asSuccess (? int $ api_code = null ): self
143
143
{
144
144
/** @noinspection PhpUnhandledExceptionInspection */
145
145
return new static (true , $ api_code ?? BaseApiCodes::OK ());
@@ -321,21 +321,21 @@ public function build(): HttpResponse
321
321
}
322
322
323
323
/**
324
- * @param boolean $success TRUE if response reports successful operation,
325
- * FALSE otherwise.
326
- * @param integer $api_code API code to be returned with the response object.
327
- * @param string|integer $msg_or_api_code Message string or valid API code to get message for
328
- * @param mixed|null $data optional additional data to be included in response.
329
- * @param integer|null $http_code HTTP code for the HttpResponse or @null for either
330
- * DEFAULT_HTTP_CODE_OK or DEFAULT_HTTP_CODE_ERROR
331
- * depending on the $success.
332
- * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message
333
- * placeholders substitution or @null if none.
334
- * @param array<string, mixed>|null $http_headers Optional HTTP headers to be returned in the response.
335
- * @param integer|null $json_opts See http://php.net/manual/en/function.json-encode.php
336
- * for supported options or pass @null to use value from
337
- * your config (or defaults).
338
- * @param array<string, mixed>|null $debug_data Optional debug data array to be added to returned JSON.
324
+ * @param boolean $success TRUE if response reports successful operation,
325
+ * FALSE otherwise.
326
+ * @param integer $api_code API code to be returned with the response object.
327
+ * @param string|integer $msg_or_api_code Message string or valid API code to get message for
328
+ * @param mixed|null $data optional additional data to be included in response.
329
+ * @param integer|null $http_code HTTP code for the HttpResponse or @null for either
330
+ * DEFAULT_HTTP_CODE_OK or DEFAULT_HTTP_CODE_ERROR
331
+ * depending on the $success.
332
+ * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message
333
+ * placeholders substitution or @null if none.
334
+ * @param array<string, mixed>|null $http_headers Optional HTTP headers to be returned in the response.
335
+ * @param integer|null $json_opts See http://php.net/manual/en/function.json-encode.php
336
+ * for supported options or pass @null to use value from
337
+ * your config (or defaults).
338
+ * @param array<string, mixed>|null $debug_data Optional debug data array to be added to returned JSON.
339
339
*
340
340
* @throws Ex\MissingConfigurationKeyException
341
341
* @throws Ex\ConfigurationNotFoundException
@@ -382,13 +382,13 @@ protected function make(bool $success,
382
382
* added to reported JSON for easier manual debugging. Returns response ready to be encoded as
383
383
* JSON and sent back to client.
384
384
*
385
- * @param boolean $success TRUE if response reports successful operation, FALSE otherwise.
386
- * @param integer $api_code Your API code to be returned with the response object.
387
- * @param string|integer $msg_or_api_code Message string or valid API code to get message for.
388
- * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message placeholders
389
- * substitution or @null if none.
390
- * @param mixed|null $data API response data if any
391
- * @param array<string, mixed>|null $debug_data optional debug data array to be added to returned JSON.
385
+ * @param boolean $success TRUE if response reports successful operation, FALSE otherwise.
386
+ * @param integer $api_code Your API code to be returned with the response object.
387
+ * @param string|integer $msg_or_api_code Message string or valid API code to get message for.
388
+ * @param array<string, mixed>|null $placeholders Placeholders passed to Lang::get() for message placeholders
389
+ * substitution or @null if none.
390
+ * @param mixed|null $data API response data if any
391
+ * @param array<string, mixed>|null $debug_data optional debug data array to be added to returned JSON.
392
392
*
393
393
* @return array<string, mixed>
394
394
*
0 commit comments