Skip to content

Commit 0e58d7f

Browse files
Merge pull request #45 from MarcinOrlowski/dev
Release v3.2.0
2 parents 694993d + 9816282 commit 0e58d7f

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

CHANGES.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# API Response Builder for Laravel 5 #
22

3-
43
See [compatibility docs](docs/compatibility.md) for details about backward compatibility!
54

6-
75
## CHANGE LOG ##
86

7+
* v3.2.0 (2017-03-02)
8+
* [RB-42] Default value of `encoding_options` include `JSON_UNESCAPED_UNICODE` to prevent unicode escaping
9+
* [RB-41] Updated documentation
10+
911
* v3.1.0 (2017-02-28)
10-
* [RB-38] Added `encoding-options` to control data-to-json conversion.
12+
* [RB-38] Added `encoding_options` to control data-to-json conversion.
1113
* [RB-38] Added optional encoding options args to all methods accepting `data` argument
1214
* [RB-34] Added option to control ExceptionHandeler behavior on debug builds
1315
* ExceptionHandler's debug is now added as `debug` node to make it more clear where it comes from
@@ -106,3 +108,4 @@ See [compatibility docs](docs/compatibility.md) for details about backward compa
106108

107109
* v1.0.0 (2016-04-11)
108110
* Initial public release
111+

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "marcin-orlowski/laravel-api-response-builder",
33
"description": "Helps building nice, normalized and easy to consume REST API responses.",
44
"homepage": "https://github.com/MarcinOrlowski/laravel-api-response-builder",
5-
"version": "3.1.0",
5+
"version": "3.2.0",
66
"keywords": [
77
"laravel",
88
"json",

config/response_builder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@
9494
| to be returned escaped, which while technically correct (ant theoretically
9595
| transparent) might not be desired effects.
9696
|
97-
| To prevent escaping, add JSON_UNESCAPED_UNICODE:
97+
| To prevent escaping, add JSON_UNESCAPED_UNICODE (default since v3.2):
9898
| JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE
9999
|
100-
| Default value:
100+
| Laravel's value:
101101
| JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT
102102
|
103103
| See http://php.net/manual/en/function.json-encode.php for details
104104
|
105105
*/
106-
'encoding_options' => JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT,
106+
'encoding_options' => JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE,
107107

108108

109109
/*

docs/docs.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Methods' arguments:
228228
* `$http_code` (**int**) valid HTTP return code (see `HttpResponse` class for useful constants),
229229
* `$lang_args` (**array**) array of arguments passed to `Lang::get()` while building `message`,
230230
* `$message` (**string**) custom message to be returned as part of error response (avoid, use error code mapping feature).
231+
* `$encoding_options` (**int**) data-to-json conversion options as [described in documentation of json_encode()](http://php.net/manual/en/function.json-encode.php). Pass `null` for default `ResponseBuilder::DEFAULT_ENCODING_OPTIONS` ([source](https://github.com/MarcinOrlowski/laravel-api-response-builder/blob/master/src/ResponseBuilder.php#L47)). See [configuration](https://github.com/MarcinOrlowski/laravel-api-response-builder/blob/master/config/response_builder.php#L106) key `encoding_options` too!
231232

232233
Most arguments of `success()` and `error()` methods are optional, with exception for `$api_code`
233234
for the latter. Helper methods arguments are partially optional - see signatures below for details.
@@ -253,8 +254,8 @@ See [W3 specs page](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) for
253254

254255
#### Reporting Success ####
255256

256-
success($data = null, $api_code = null, array $lang_args = [], $http_code = null);
257-
successWithCode($api_code = null, array $lang_args = [], $http_code = null);
257+
success($data=null, $api_code=null, array $lang_args=[], $http_code=null, $encoding_options=null);
258+
successWithCode($api_code=null, array $lang_args=[], $http_code=null);
258259
successWithHttpCode($http_code);
259260

260261
Usage restrictions:
@@ -263,11 +264,11 @@ Usage restrictions:
263264

264265
#### Reporting Error ####
265266

266-
error($api_code, $lang_args = [], $data = null, $http_code = HttpResponse::HTTP_BAD_REQUEST);
267-
errorWithData($api_code, $data, array $lang_args = []);
268-
errorWithDataAndHttpCode($api_code, $data, $http_code, array $lang_args = []);
269-
errorWithHttpCode($api_code, $http_code, $lang_args = []);
270-
errorWithMessage($api_code, $error_message, $http_code = HttpResponse::HTTP_BAD_REQUEST);
267+
error($api_code, $lang_args=[], $data=null, $http_code=HttpResponse::HTTP_BAD_REQUEST);
268+
errorWithData($api_code, $data, array $lang_args=[], $encoding_options=null);
269+
errorWithDataAndHttpCode($api_code, $data, $http_code, array $lang_args=[], $encoding_options=null);
270+
errorWithHttpCode($api_code, $http_code, $lang_args=[]);
271+
errorWithMessage($api_code, $error_message, $http_code=HttpResponse::HTTP_BAD_REQUEST);
271272

272273
Usage restrictions:
273274

src/ResponseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class ResponseBuilder
4040
/**
4141
* Default JSON encoding options
4242
*
43-
* 15 = JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT
43+
* 271 = JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE
4444
*
4545
* This must be as int due to const limits in PHP disallowing expressions.
4646
*/
47-
const DEFAULT_ENCODING_OPTIONS = 15;
47+
const DEFAULT_ENCODING_OPTIONS = 271;
4848

4949
/**
5050
* Reads and validates "classes" config mapping

tests/InternalsTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ public function testMake_InvalidEncodingOptions()
6969
}
7070

7171
/**
72-
* Tests if JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT matches const value of DEFAULT_ENODING_OPTIONS
72+
* Tests if dist's config detaults matches ResponseBuilder::DEFAULT_ENODING_OPTIONS
7373
*
7474
* @return void
7575
*/
7676
public function testDefaultEncodingOptionValue()
7777
{
78-
$this->assertEquals(JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT, ResponseBuilder::DEFAULT_ENCODING_OPTIONS);
78+
$config_defaults = \Config::get('response_builder.encoding_options');
79+
$this->assertEquals($config_defaults, ResponseBuilder::DEFAULT_ENCODING_OPTIONS);
7980
}
8081

8182
/**
@@ -87,7 +88,7 @@ public function testMake_DefaultEncodingOptions()
8788
{
8889
// source data
8990
$test_string = 'ąćę';
90-
$test_string_escaped = $this->escape8($test_string);
91+
// $test_string_escaped = $this->escape8($test_string);
9192
$data = ['test' => $test_string];
9293

9394
// fallback defaults in action

0 commit comments

Comments
 (0)