@@ -12,117 +12,117 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | return [ |
15 | - /* |
|
15 | + /* |
|
16 | 16 | |----------------------------------------------------------------------------------------------------------- |
17 | 17 | | Code range settings |
18 | 18 | |----------------------------------------------------------------------------------------------------------- |
19 | 19 | */ |
20 | - 'min_code' => 100, |
|
21 | - 'max_code' => 1024, |
|
20 | + 'min_code' => 100, |
|
21 | + 'max_code' => 1024, |
|
22 | 22 | |
23 | - /* |
|
23 | + /* |
|
24 | 24 | |----------------------------------------------------------------------------------------------------------- |
25 | 25 | | Error code to message mapping |
26 | 26 | |----------------------------------------------------------------------------------------------------------- |
27 | 27 | | |
28 | 28 | */ |
29 | - 'map' => [ |
|
30 | - // YOUR_API_CODE => '<MESSAGE_KEY>', |
|
31 | - ], |
|
29 | + 'map' => [ |
|
30 | + // YOUR_API_CODE => '<MESSAGE_KEY>', |
|
31 | + ], |
|
32 | 32 | |
33 | - /* |
|
33 | + /* |
|
34 | 34 | |----------------------------------------------------------------------------------------------------------- |
35 | 35 | | Response Builder data converter |
36 | 36 | |----------------------------------------------------------------------------------------------------------- |
37 | 37 | | |
38 | 38 | */ |
39 | - 'converter' => [ |
|
40 | - 'primitives' => [ |
|
41 | - /* Configuration for primitives used when such data is passed directly as payload (i.e. `success(15)`;) */ |
|
42 | - 'array' => [ |
|
43 | - 'key' => 'values', |
|
44 | - ], |
|
45 | - 'boolean' => [ |
|
46 | - 'key' => 'value', |
|
47 | - ], |
|
48 | - 'double' => [ |
|
49 | - 'key' => 'value', |
|
50 | - ], |
|
51 | - 'integer' => [ |
|
52 | - 'key' => 'value', |
|
53 | - ], |
|
54 | - 'string' => [ |
|
55 | - 'key' => 'value', |
|
56 | - ], |
|
57 | - ], |
|
58 | - |
|
59 | - /* Object converters configuration for supported classes */ |
|
60 | - 'classes' => [ |
|
61 | - \Illuminate\Database\Eloquent\Model::class => [ |
|
62 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
63 | - 'key' => 'item', |
|
64 | - 'pri' => 0, |
|
65 | - ], |
|
66 | - \Illuminate\Support\Collection::class => [ |
|
67 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
68 | - 'key' => 'items', |
|
69 | - 'pri' => 0, |
|
70 | - ], |
|
71 | - \Illuminate\Database\Eloquent\Collection::class => [ |
|
72 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
73 | - 'key' => 'items', |
|
74 | - 'pri' => 0, |
|
75 | - ], |
|
76 | - \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
77 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
78 | - 'key' => 'item', |
|
79 | - 'pri' => 0, |
|
80 | - ], |
|
81 | - |
|
82 | - /* |
|
39 | + 'converter' => [ |
|
40 | + 'primitives' => [ |
|
41 | + /* Configuration for primitives used when such data is passed directly as payload (i.e. `success(15)`;) */ |
|
42 | + 'array' => [ |
|
43 | + 'key' => 'values', |
|
44 | + ], |
|
45 | + 'boolean' => [ |
|
46 | + 'key' => 'value', |
|
47 | + ], |
|
48 | + 'double' => [ |
|
49 | + 'key' => 'value', |
|
50 | + ], |
|
51 | + 'integer' => [ |
|
52 | + 'key' => 'value', |
|
53 | + ], |
|
54 | + 'string' => [ |
|
55 | + 'key' => 'value', |
|
56 | + ], |
|
57 | + ], |
|
58 | + |
|
59 | + /* Object converters configuration for supported classes */ |
|
60 | + 'classes' => [ |
|
61 | + \Illuminate\Database\Eloquent\Model::class => [ |
|
62 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
63 | + 'key' => 'item', |
|
64 | + 'pri' => 0, |
|
65 | + ], |
|
66 | + \Illuminate\Support\Collection::class => [ |
|
67 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
68 | + 'key' => 'items', |
|
69 | + 'pri' => 0, |
|
70 | + ], |
|
71 | + \Illuminate\Database\Eloquent\Collection::class => [ |
|
72 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
73 | + 'key' => 'items', |
|
74 | + 'pri' => 0, |
|
75 | + ], |
|
76 | + \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
77 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
78 | + 'key' => 'item', |
|
79 | + 'pri' => 0, |
|
80 | + ], |
|
81 | + |
|
82 | + /* |
|
83 | 83 | |----------------------------------------------------------------------------------------------------------- |
84 | 84 | | Paginators converts to objects already, so we do not array wrapping here, hence setting `key` to null |
85 | 85 | |----------------------------------------------------------------------------------------------------------- |
86 | 86 | */ |
87 | 87 | |
88 | - \Illuminate\Pagination\LengthAwarePaginator::class => [ |
|
89 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
90 | - 'key' => null, |
|
91 | - 'pri' => 0, |
|
92 | - ], |
|
93 | - \Illuminate\Pagination\Paginator::class => [ |
|
94 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
95 | - 'key' => null, |
|
96 | - 'pri' => 0, |
|
97 | - ], |
|
98 | - |
|
99 | - /* |
|
88 | + \Illuminate\Pagination\LengthAwarePaginator::class => [ |
|
89 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
90 | + 'key' => null, |
|
91 | + 'pri' => 0, |
|
92 | + ], |
|
93 | + \Illuminate\Pagination\Paginator::class => [ |
|
94 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
95 | + 'key' => null, |
|
96 | + 'pri' => 0, |
|
97 | + ], |
|
98 | + |
|
99 | + /* |
|
100 | 100 | |----------------------------------------------------------------------------------------------------------- |
101 | 101 | | Generic converters should have lower pri to allow dedicated ones to kick in first when class matches |
102 | 102 | |----------------------------------------------------------------------------------------------------------- |
103 | 103 | */ |
104 | - \JsonSerializable::class => [ |
|
105 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\JsonSerializableConverter::class, |
|
106 | - 'key' => 'item', |
|
107 | - 'pri' => -10, |
|
108 | - ], |
|
109 | - \Illuminate\Contracts\Support\Arrayable::class => [ |
|
110 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
111 | - 'key' => 'items', |
|
112 | - 'pri' => -10, |
|
113 | - ], |
|
114 | - ], |
|
115 | - |
|
116 | - ], |
|
117 | - |
|
118 | - /* |
|
104 | + \JsonSerializable::class => [ |
|
105 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\JsonSerializableConverter::class, |
|
106 | + 'key' => 'item', |
|
107 | + 'pri' => -10, |
|
108 | + ], |
|
109 | + \Illuminate\Contracts\Support\Arrayable::class => [ |
|
110 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
111 | + 'key' => 'items', |
|
112 | + 'pri' => -10, |
|
113 | + ], |
|
114 | + ], |
|
115 | + |
|
116 | + ], |
|
117 | + |
|
118 | + /* |
|
119 | 119 | |----------------------------------------------------------------------------------------------------------- |
120 | 120 | | Exception handler error codes |
121 | 121 | |----------------------------------------------------------------------------------------------------------- |
122 | 122 | | |
123 | 123 | */ |
124 | - 'exception_handler' => [ |
|
125 | - /* |
|
124 | + 'exception_handler' => [ |
|
125 | + /* |
|
126 | 126 | * The following keys are supported for each handler specified. |
127 | 127 | * `handler` |
128 | 128 | * `pri` |
@@ -142,19 +142,19 @@ discard block |
||
142 | 142 | * message ($ex->getMessage()). |
143 | 143 | */ |
144 | 144 | |
145 | - \Illuminate\Validation\ValidationException::class => [ |
|
146 | - 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\ValidationExceptionHandler::class, |
|
147 | - 'pri' => -100, |
|
148 | - 'config' => [ |
|
145 | + \Illuminate\Validation\ValidationException::class => [ |
|
146 | + 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\ValidationExceptionHandler::class, |
|
147 | + 'pri' => -100, |
|
148 | + 'config' => [ |
|
149 | 149 | // 'api_code' => ApiCodes::YOUR_API_CODE_FOR_VALIDATION_EXCEPTION, |
150 | 150 | // 'http_code' => HttpResponse::HTTP_UNPROCESSABLE_ENTITY, |
151 | - ], |
|
152 | - ], |
|
151 | + ], |
|
152 | + ], |
|
153 | 153 | |
154 | 154 | \Symfony\Component\HttpKernel\Exception\HttpException::class => [ |
155 | - 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
156 | - 'pri' => -100, |
|
157 | - 'config' => [ |
|
155 | + 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
156 | + 'pri' => -100, |
|
157 | + 'config' => [ |
|
158 | 158 | // HttpException::class => [ |
159 | 159 | // // used by unauthenticated() to obtain api and http code for the exception |
160 | 160 | // HttpResponse::HTTP_UNAUTHORIZED => [ |
@@ -170,47 +170,47 @@ discard block |
||
170 | 170 | // 'http_code' => HttpResponse::HTTP_BAD_REQUEST, |
171 | 171 | // ], |
172 | 172 | // ], |
173 | - ], |
|
173 | + ], |
|
174 | 174 | // // This is final exception handler. If ex is not dealt with yet this is its last stop. |
175 | - // default handler is mandatory and MUST have both `api_code` and `http_code` set. |
|
175 | + // default handler is mandatory and MUST have both `api_code` and `http_code` set. |
|
176 | 176 | |
177 | - 'default' => [ |
|
178 | - 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
179 | - 'pri' => -127, |
|
180 | - 'config' => [ |
|
177 | + 'default' => [ |
|
178 | + 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
179 | + 'pri' => -127, |
|
180 | + 'config' => [ |
|
181 | 181 | // 'api_code' => ApiCodes::YOUR_API_CODE_FOR_UNHANDLED_EXCEPTION, |
182 | 182 | // 'http_code' => HttpResponse::HTTP_INTERNAL_SERVER_ERROR, |
183 | - ], |
|
184 | - ], |
|
185 | - ], |
|
186 | - ], |
|
183 | + ], |
|
184 | + ], |
|
185 | + ], |
|
186 | + ], |
|
187 | 187 | |
188 | - /* |
|
188 | + /* |
|
189 | 189 | |----------------------------------------------------------------------------------------------------------- |
190 | 190 | | data-to-json encoding options |
191 | 191 | |----------------------------------------------------------------------------------------------------------- |
192 | 192 | | |
193 | 193 | */ |
194 | - 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
194 | + 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
195 | 195 | |
196 | - /* |
|
196 | + /* |
|
197 | 197 | |----------------------------------------------------------------------------------------------------------- |
198 | 198 | | Debug config |
199 | 199 | |----------------------------------------------------------------------------------------------------------- |
200 | 200 | | |
201 | 201 | */ |
202 | - 'debug' => [ |
|
203 | - 'debug_key' => 'debug', |
|
204 | - 'exception_handler' => [ |
|
205 | - 'trace_key' => 'trace', |
|
206 | - 'trace_enabled' => env('APP_DEBUG', false), |
|
207 | - ], |
|
208 | - |
|
209 | - // Controls debugging features of payload converter class. |
|
210 | - 'converter' => [ |
|
211 | - // Set to true to figure out what converter is used for given data payload and why. |
|
212 | - 'debug_enabled' => env('RB_CONVERTER_DEBUG', false), |
|
213 | - ], |
|
214 | - ], |
|
202 | + 'debug' => [ |
|
203 | + 'debug_key' => 'debug', |
|
204 | + 'exception_handler' => [ |
|
205 | + 'trace_key' => 'trace', |
|
206 | + 'trace_enabled' => env('APP_DEBUG', false), |
|
207 | + ], |
|
208 | + |
|
209 | + // Controls debugging features of payload converter class. |
|
210 | + 'converter' => [ |
|
211 | + // Set to true to figure out what converter is used for given data payload and why. |
|
212 | + 'debug_enabled' => env('RB_CONVERTER_DEBUG', false), |
|
213 | + ], |
|
214 | + ], |
|
215 | 215 | |
216 | 216 | ]; |