File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
src/Elasticsearch/Serializers Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use Elasticsearch \Common \Exceptions \RuntimeException ;
8
8
9
+ if (!defined ('JSON_INVALID_UTF8_SUBSTITUTE ' )) {
10
+ //PHP < 7.2 Define it as 0 so it does nothing
11
+ define ('JSON_INVALID_UTF8_SUBSTITUTE ' , 0 );
12
+ }
13
+
9
14
/**
10
15
* Class JSONSerializer
11
16
*
@@ -25,7 +30,7 @@ public function serialize($data): string
25
30
if (is_string ($ data ) === true ) {
26
31
return $ data ;
27
32
} else {
28
- $ data = json_encode ($ data , JSON_PRESERVE_ZERO_FRACTION );
33
+ $ data = json_encode ($ data , JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE );
29
34
if ($ data === false ) {
30
35
throw new RuntimeException ("Failed to JSON encode: " .json_last_error ());
31
36
}
Original file line number Diff line number Diff line change 6
6
7
7
use Elasticsearch \Common \Exceptions \RuntimeException ;
8
8
9
+ if (!defined ('JSON_INVALID_UTF8_SUBSTITUTE ' )) {
10
+ //PHP < 7.2 Define it as 0 so it does nothing
11
+ define ('JSON_INVALID_UTF8_SUBSTITUTE ' , 0 );
12
+ }
13
+
9
14
/**
10
15
* Class EverythingToJSONSerializer
11
16
*
@@ -22,7 +27,7 @@ class EverythingToJSONSerializer implements SerializerInterface
22
27
*/
23
28
public function serialize ($ data ): string
24
29
{
25
- $ data = json_encode ($ data , JSON_PRESERVE_ZERO_FRACTION );
30
+ $ data = json_encode ($ data , JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE );
26
31
if ($ data === false ) {
27
32
throw new RuntimeException ("Failed to JSON encode: " .json_last_error ());
28
33
}
Original file line number Diff line number Diff line change 7
7
use Elasticsearch \Common \Exceptions ;
8
8
use Elasticsearch \Common \Exceptions \Serializer \JsonErrorException ;
9
9
10
+ if (!defined ('JSON_INVALID_UTF8_SUBSTITUTE ' )) {
11
+ //PHP < 7.2 Define it as 0 so it does nothing
12
+ define ('JSON_INVALID_UTF8_SUBSTITUTE ' , 0 );
13
+ }
14
+
10
15
/**
11
16
* Class SmartSerializer
12
17
*
@@ -26,7 +31,7 @@ public function serialize($data): string
26
31
if (is_string ($ data ) === true ) {
27
32
return $ data ;
28
33
} else {
29
- $ data = json_encode ($ data , JSON_PRESERVE_ZERO_FRACTION );
34
+ $ data = json_encode ($ data , JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE );
30
35
if ($ data === false ) {
31
36
throw new Exceptions \RuntimeException ("Failed to JSON encode: " .json_last_error ());
32
37
}
You can’t perform that action at this time.
0 commit comments