You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/config.md
+32-24Lines changed: 32 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,25 +66,35 @@
66
66
Meaning of parameters:
67
67
68
68
*`handler` (mandatory) specifies a full name of the class implementing `ConverterContract`. Object of that class will be
69
-
instantiated and conversion method will be invoked with object given as argument. The `key` is a string that will be used
70
-
as the JSON response as key to array representation when object of that class is passed as direct payload
71
-
(i.e. `success($object);`). Note, that `key` is not used otherwise, so if you have i.e. array of objects, they will be
72
-
properly converted without `key` used.
73
-
*`key` (mandatory) can be a string or `NULL`. A string is useful for some converters when dealing with an object of a given class being returned directly
74
-
as response payload (i.e. `success($collection)`). Otherwise `NULL` can be used to tell `ResponseBuilder` to return object directly, which may be useful.
69
+
instantiated and conversion method invoked with object to convert passed as method argument.
70
+
*`key` (mandatory) can be a string or `NULL`. When dealing with an object of a given class being returned directly
71
+
as response payload (i.e. `success($collection)`), the `key` string will be used in returned JSON as converted data
72
+
key. Passing `NULL` tells `ResponseBuilder` to return object without using the key, which is useful while dealing
73
+
with i.e. collection of objects as collection will be `key`ed in the response, but objects should be returned as
74
+
plain JSON array.
75
+
76
+
77
+
```json
78
+
...
79
+
"data": {
80
+
"given-key": {
81
+
[converted object data]
82
+
}
83
+
}
84
+
...
85
+
```
86
+
87
+
75
88
*`pri` (optional) is an integer being entry's priority (default `0`). Entries with higher values will be matched first. If you got one
76
89
class extending another and you want to support both of them with separate configuration, then you **must** ensure child
77
90
class has higher priority than it's parent class.
78
91
79
-
The above configures two classes (`Model` and `Collection`). Whenever object of that class is spotted, method specified in
80
-
`method` key would be called on that object and data that method returns will be returned in JSON object.
81
-
82
92
All configuration entries are assigned priority `0` which can be changed using `pri` key (integer). This value is used to
83
93
sort the entries to ensure that matching order is preserved. Entries with higher priority are matched first etc. This is
84
94
very useful when you want to indirect configuration for two classes where additionally second extends first one.
85
95
So if you have class `A` and `B` that extends `A` and you want different handling for `B` than you have set for `A`
86
96
then `B` related configuration must be set with higher priority.
87
-
97
+
88
98
>  For each object `ResponseBuilder` checks if we have configuration entry matching **exactly**
89
99
> object class name. If no such mapping is found, then the whole configuration is walked again, but this time we take inheritance
90
100
> into consideration and use `instanceof` to see if we have a match, therefore you need to pay attention your config specifies
@@ -140,17 +150,17 @@ $data = [
140
150
*`integer`
141
151
*`string`
142
152
143
-
For each of these types there's configuration entry in `primitives` node of `converter` config, consisting of `key` entry.
144
-
The value of `key`is an arbitrary string, that will be used when given primivite will be passed as direct payload. For example,
145
-
pre v9 would require
153
+
For each of these types there's configuration entry in `primitives` node of `converter` config. Each entry defined `key`
154
+
which is an arbitrary string, used for given primitive. The default value for all supported primitives is `value`.
155
+
For example, pre v9 would require
146
156
147
-
RB::success(['my_key' => 12.25]);
157
+
RB::success(['value' => 12.25]);
148
158
149
159
while with v9+ if can be simplified:
150
160
151
161
RB::success(12.25);
152
162
153
-
and both would produce the same
163
+
and both would yield the same result:
154
164
155
165
```json
156
166
{
@@ -159,15 +169,16 @@ and both would produce the same
159
169
"locale": "en",
160
170
"message": "OK",
161
171
"data": {
162
-
"my_key": 12.25
172
+
"value": 12.25
163
173
}
164
174
}
165
175
```
166
176
167
-
assuming string`my_key` is the value of `key` entry for primitive type `double`.
168
-
169
177
### debug ###
170
178
179
+
>  Do not use debug mode on production as it may expose i.e. your filesystem structure
180
+
> or class names or other internals that should not really be public.
181
+
171
182
```php
172
183
'debug' => [
173
184
'debug_key' => 'debug',
@@ -187,12 +198,8 @@ assuming string`my_key` is the value of `key` entry for primitive type `double`.
187
198
```
188
199
189
200
`debug_key` - name of the JSON key trace data should be put under when in `debug` node.
190
-
191
-
/**
192
-
* When ExceptionHandler kicks in and this is set to @true,
193
-
* then returned JSON structure will contain additional debug data
194
-
* with information about class name, file name and line number.
195
-
*/
201
+
When `ExceptionHandler` kicks with debug mode enabled, returned JSON structure would
202
+
contain additional debug data with information about class name, file name and line number:
196
203
197
204
```json
198
205
{
@@ -210,6 +217,7 @@ assuming string`my_key` is the value of `key` entry for primitive type `double`.
210
217
}
211
218
}
212
219
```
220
+
213
221
### encoding_options ###
214
222
215
223
This option controls data JSON encoding. Since v3.1, encoding was relying on framework's defaults, however this
0 commit comments