Skip to content

Commit e48a8e8

Browse files
authored
Merge pull request #1023 from szabosteve/7.x.serial.version
[DOCS] Fine-tunes serializers and required PHP version pages in the PHP book
2 parents 00a7111 + f9717cf commit e48a8e8

File tree

2 files changed

+74
-49
lines changed

2 files changed

+74
-49
lines changed

docs/php-version-requirement.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
== PHP Version Requirement
33

44
Version 7.0 of Elasticsearch-PHP requires PHP version 7.1.0 or higher.
5-
In addition, it requires the native JSON extension to be version 1.3.7 or higher.
5+
6+
In addition, it requires the native JSON extension to be version 1.3.7 or
7+
higher.

docs/serializers.asciidoc

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
[[serializers]]
22
== Serializers
33

4-
The client has three serializers available. You will most likely never need
5-
to change the serializer, unless you have special requirements or are
4+
The client has three serializers available. You will most likely never need
5+
to change the serializer, unless you have special requirements or are
66
implementing a new protocol.
77

8-
The job of the serializer is to encode the outgoing request body and decode
9-
the incoming response body. In 99% of cases, this is a simple conversion
10-
to/from JSON.
8+
The job of the serializer is to encode the outgoing request body and decode the
9+
incoming response body. In 99% of cases, this is a simple conversion to/from
10+
JSON.
11+
12+
The default serializer is the `SmartSerializer`.
1113

12-
The default serializer is the `SmartSerializer`
1314

1415
=== SmartSerializer
16+
1517
==== Serialize()
16-
The `SmartSerializer` inspects the data to be encoded. If the request body
17-
is provided as a string, it is passed directly to Elasticsearch as a string.
18-
This allows users to provide raw JSON, or raw strings for certain endpoints that
19-
dont have structure (such as the Analyze endpoint).
20-
21-
If the data is an array, it is converted to json. If the data provided was an
22-
empty array, the serializer manually converts the JSON from an empty array (`[]`)
23-
to an empty object (`{}`) so that it is valid JSON for Elasticsearch request
18+
19+
The `SmartSerializer` inspects the data to be encoded. If the request body is
20+
provided as a string, it is passed directly to {es} as a string. This allows
21+
users to provide raw JSON, or raw strings for certain endpoints that don't have
22+
structure (such as the Analyze endpoint).
23+
24+
If the data is an array, it is converted to JSON. If the data provided was an
25+
empty array, the serializer manually converts the JSON from an empty array
26+
(`[]`) to an empty object (`{}`) so that it is valid JSON for {es} request
2427
bodies.
2528

2629
==== Deserialize()
27-
When decoding the response body, the `SmartSerializer` introspects the
28-
`content_type` headers to determine the appropriate encoding. If the data is
29-
encoded as JSON, it is decoded into an array using `json_decode`. Otherwise,
30-
it is returned as a string.
3130

32-
This functionality is required to cooperate with endpoints such as the `Cat`
31+
When decoding the response body, the `SmartSerializer` introspects the
32+
`content_type` headers to determine the appropriate encoding. If the data is
33+
encoded as JSON, it is decoded into an array using `json_decode`. Otherwise, it
34+
is returned as a string.
35+
36+
This functionality is required to cooperate with endpoints such as the `Cat`
3337
endpoints, which return tabular text instead of JSON.
3438

39+
3540
==== Selecting the SmartSerializer
3641

37-
The SmartSerializer is selected by default, but if you wish to manually configure it for explicitness, you can
38-
do so by using the `setSerializer()` method on the ClientBuilder object:
42+
The `SmartSerializer` is selected by default, but if you wish to manually
43+
configure it for explicitness, you can do so by using the `setSerializer()`
44+
method on the `ClientBuilder` object:
3945

4046
[source,php]
4147
----
@@ -44,27 +50,36 @@ $client = ClientBuilder::create()
4450
->build();
4551
----
4652

47-
Note that the serializer is configured by specifying a namespace path to the serializer.
53+
Note that the serializer is configured by specifying a namespace path to the
54+
serializer.
55+
4856

4957
=== ArrayToJSONSerializer
58+
5059
==== Serialize()
51-
The `ArrayToJSONSerializer` inspects the data to be encoded. If the request body
52-
is provided as a string, it is passed directly to Elasticsearch as a string.
53-
This allows users to provide raw JSON, or raw strings for certain endpoints that
54-
dont have structure (such as the Analyze endpoint).
55-
56-
If the data is an array, it is converted to json. If the data provided was an
57-
empty array, the serializer manually converts the JSON from an empty array (`[]`)
58-
to an empty object (`{}`) so that it is valid JSON for Elasticsearch request
60+
61+
The `ArrayToJSONSerializer` inspects the data to be encoded. If the request body
62+
is provided as a string, it is passed directly to {es} as a string. This allows
63+
users to provide raw JSON, or raw strings for certain endpoints that don't have
64+
structure (such as the Analyze endpoint).
65+
66+
If the data is an array, it is converted to json. If the data provided was an
67+
empty array, the serializer manually converts the JSON from an empty array
68+
(`[]`) to an empty object (`{}`) so that it is valid JSON for {es} request
5969
bodies.
6070

71+
6172
==== Deserialize()
62-
When decoding the response body, everything is decoded to JSON from JSON. If
63-
the data is not valid JSON, `null` will be returned.
73+
74+
When decoding the response body, everything is decoded to JSON from JSON. If the
75+
data is not valid JSON, `null` will be returned.
76+
6477

6578
==== Selecting the ArrayToJSONSerializer
6679

67-
You can select `ArrayToJSONSerializer` by using the `setSerializer()` method on the ClientBuilder object:
80+
You can select `ArrayToJSONSerializer` by using the `setSerializer()` method on
81+
the `ClientBuilder` object:
82+
6883

6984
[source,php]
7085
----
@@ -73,26 +88,32 @@ $client = ClientBuilder::create()
7388
->build();
7489
----
7590

76-
Note that the serializer is configured by specifying a namespace path to the serializer.
91+
Note that the serializer is configured by specifying a namespace path to the
92+
serializer.
93+
7794

7895
=== EverythingToJSONSerializer
96+
7997
==== Serialize()
98+
8099
The `EverythingToJSONSerializer` tries to convert everything to JSON.
81100

82-
If the data provided was an empty array, the serializer manually converts the
101+
If the data provided was an empty array, the serializer manually converts the
83102
JSON from an empty array (`[]`) to an empty object (`{}`) so that it is valid
84103
JSON for Elasticsearch request bodies.
85104

86105
If the data was not an array and/or not convertible to JSON, the method returns
87106
`null`.
88107

89108
==== Deserialize()
90-
When decoding the response body, everything is decoded to JSON from JSON. If
91-
the data is not valid JSON, `null` will be returned.
109+
110+
When decoding the response body, everything is decoded to JSON from JSON. If the
111+
data is not valid JSON, `null` is returned.
92112

93113
==== Selecting the EverythingToJSONSerializer
94114

95-
You can select `EverythingToJSONSerializer` by using the `setSerializer()` method on the ClientBuilder object:
115+
You can select `EverythingToJSONSerializer` by using the `setSerializer()`
116+
method on the ClientBuilder object:
96117

97118
[source,php]
98119
----
@@ -101,11 +122,14 @@ $client = ClientBuilder::create()
101122
->build();
102123
----
103124

104-
Note that the serializer is configured by specifying a namespace path to the serializer.
125+
Note that the serializer is configured by specifying a namespace path to the
126+
serializer.
105127

106128
=== Implementing your own Serializer
107-
If you want to use your own custom serializer, you need to implement the `SerializerInterface` interface. Please
108-
keep in mind that the client uses a single Serializer object for all endpoints and all connections.
129+
130+
If you want to use your own custom serializer, you need to implement the
131+
`SerializerInterface` interface. Please keep in mind that the client uses a
132+
single Serializer object for all endpoints and all connections.
109133

110134

111135
[source,php]
@@ -141,8 +165,8 @@ class MyCustomSerializer implements SerializerInterface
141165
----
142166
{zwsp} +
143167

144-
To then use your custom serializer, you can specify the namespace path in the `setSerializer()` method of the ClientBuilder
145-
object:
168+
To then use your custom serializer, you can specify the namespace path in the
169+
`setSerializer()` method of the `ClientBuilder` object:
146170

147171
[source,php]
148172
----
@@ -151,8 +175,9 @@ $client = ClientBuilder::create()
151175
->build();
152176
----
153177

154-
Alternatively, if your serializer has a constructor or further initialization that should occur before given to the
155-
client, you can instantiate an object and provide that instead:
178+
Alternatively, if your serializer has a constructor or further initialization
179+
that should occur before given to the client, you can instantiate an object and
180+
provide that instead:
156181

157182
[source,php]
158183
----
@@ -162,6 +187,4 @@ $mySerializer->setFoo("bar");
162187
$client = ClientBuilder::create()
163188
->setSerializer($mySerializer);
164189
->build();
165-
----
166-
167-
190+
----

0 commit comments

Comments
 (0)