@@ -7,7 +7,7 @@ provides more options to customize the output, which makes it easier to generate
7
7
code for different kinds of purposes such as readable configuration files or
8
8
optimized cache files.
9
9
10
- The purpose of this library is to address some of the shortcomings with the
10
+ The purpose of this library is to address some of the shortcomings with the
11
11
built in ` var_export() ` . For example, there is no way to control the amount of
12
12
whitespace in the output and there is no way to choose between different array
13
13
notations. This library also provides functionality to convert objects into PHP
@@ -24,13 +24,15 @@ at: http://kit.riimu.net/api/phpencoder/
24
24
[ ![ Build Status] ( https://img.shields.io/travis/Riimu/Kit-PHPEncoder.svg?style=flat )] ( https://travis-ci.org/Riimu/Kit-PHPEncoder )
25
25
[ ![ Code Coverage] ( https://img.shields.io/scrutinizer/coverage/g/Riimu/Kit-PHPEncoder.svg?style=flat )] ( https://scrutinizer-ci.com/g/Riimu/Kit-PHPEncoder/ )
26
26
[ ![ Scrutinizer Code Quality] ( https://img.shields.io/scrutinizer/g/Riimu/Kit-PHPEncoder.svg?style=flat )] ( https://scrutinizer-ci.com/g/Riimu/Kit-PHPEncoder/ )
27
+ [ ![ HHVM Status] ( https://img.shields.io/hhvm/riimu/kit-phpencoder.svg )] ( http://hhvm.h4cc.de/package/riimu/kit-phpencoder )
28
+ ![ PHP7 Status] ( https://img.shields.io/badge/PHP7-tested-brightgreen.svg )
27
29
28
30
## Requirements ##
29
31
30
32
In order to use this library, the following requirements must be met:
31
33
32
34
* PHP version 5.4
33
-
35
+
34
36
## Installation ##
35
37
36
38
This library can be installed by using [ Composer] ( http://getcomposer.org/ ) . In
@@ -87,7 +89,7 @@ echo $encoder->encode(['foo' => 'bar', [1, true, false, null, 1.0]]);
87
89
88
90
This would create the following output:
89
91
90
- ```
92
+ ```
91
93
[
92
94
'foo' => 'bar',
93
95
[1, true, false, null, 1.0],
@@ -137,107 +139,107 @@ is possible to set these options in three different ways:
137
139
* Option values can be set via the ` setOption() ` method.
138
140
* Options can be passed as an array as the second argument to the ` encode() `
139
141
method.
140
-
142
+
141
143
Note that options passed to the ` encode() ` method are only temporary and do not
142
144
apply to following calls.
143
145
144
146
#### List of Options ####
145
147
146
- * ** whitespace** : < ; boolean> ; (true)
148
+ * ** whitespace** : < ; boolean> ; (true)< br >
147
149
When set to ` false ` , generation of all extra whitespace is disabled and all
148
150
other settings that affect whitespace are ignored.
149
-
150
- * ** null.capitalize** : < ; boolean> ; (false)
151
+
152
+ * ** null.capitalize** : < ; boolean> ; (false)< br >
151
153
When set to ` true ` , all ` null ` values are written in upper case instead of
152
- lower case.
153
-
154
- * ** boolean.capitalize** : < ; boolean> ; (false)
154
+ lower case.
155
+
156
+ * ** boolean.capitalize** : < ; boolean> ; (false)< br >
155
157
When set to ` true ` , all ` true ` and ` false ` values are written in upper case
156
158
instead of lower case.
157
-
158
- * ** float.integers** : < ; boolean|"all"> ; (false)
159
+
160
+ * ** float.integers** : < ; boolean|"all"> ; (false)< br >
159
161
When set to ` true ` , any float that represents an integer and has a value
160
162
that is accurately represented by the floating point number will be encoded
161
163
as an integer instead of a float. (e.g. the value ` 2.0 ` will be encoded as
162
164
` 2 ` ). To include the values that are not accurately represented, you may set
163
165
option to ` "all" ` .
164
-
165
- * ** float.precision** : < ; integer|false> ; (17)
166
+
167
+ * ** float.precision** : < ; integer|false> ; (17)< br >
166
168
The maximum precision of encoded floating point values, which usually also
167
169
means the maximum number of digits in encoded floats. If the value is set to
168
170
` false ` , the PHP ini setting ` serialize_precision ` will be used instead.
169
171
Note that due to the way floating point values work, a value greater than 17
170
172
does not provide any additional precision.
171
-
172
- * ** string.escape** : < ; boolean> ; (true)
173
+
174
+ * ** string.escape** : < ; boolean> ; (true)< br >
173
175
When set to ` true ` , all strings containing bytes outside the 32-126 ASCII
174
176
range will be written with double quotes and the characters outside the
175
177
range will be escaped.
176
-
177
- * ** array.short** : < ; boolean> ; (true)
178
+
179
+ * ** array.short** : < ; boolean> ; (true)< br >
178
180
When set to ` true ` , arrays are enclosed using square brackets ` [] ` instead
179
181
using of the long array notation ` array() ` .
180
-
181
- * ** array.base** : < ; integer|string> ; (0)
182
+
183
+ * ** array.base** : < ; integer|string> ; (0)< br >
182
184
Base indentation for arrays as a number of spaces or as a string. Provides
183
185
convenience when you need to output code to a file with specific level of
184
186
indentation.
185
-
186
- * ** array.indent** : < ; integer|string> ; (4)
187
+
188
+ * ** array.indent** : < ; integer|string> ; (4)< br >
187
189
Amount of indentation for single level of indentation as a number of spaces
188
190
or a string.
189
-
190
- * ** array.align** : < ; boolean> ; (false)
191
+
192
+ * ** array.align** : < ; boolean> ; (false)< br >
191
193
When set to ` true ` , array assignment operators ` => ` are aligned to the same
192
194
column using spaces. Even if enabled, ` array.omit ` and ` array.inline `
193
- options are still respected, but only if all the keys in the specific array
195
+ options are still respected, but only if all the keys in the specific array
194
196
can be omitted.
195
-
196
- * ** array.inline** : < ; boolean|integer> ; (70)
197
+
198
+ * ** array.inline** : < ; boolean|integer> ; (70)< br >
197
199
When set to ` true ` , any array that can be written without any array keys
198
200
will be written in a single line. If an integer is provided instead, the
199
201
array will be written as a single line only if it does not exceed that
200
202
number of characters. This option has no effect when ` array.omit ` is set to
201
203
false.
202
-
203
- * ** array.omit** : < ; boolean> ; (true)
204
+
205
+ * ** array.omit** : < ; boolean> ; (true)< br >
204
206
When set to ` true ` , any redundant array keys will not be included (e.g. the
205
207
array ` [0 => 'a', 1 => 'b'] ` would be encoded just as ` ['a', 'b'] ` ).
206
-
207
- * ** array.eol** : < ; string|false> ; (false)
208
+
209
+ * ** array.eol** : < ; string|false> ; (false)< br >
208
210
The end of line character used by array output. When set to ` false ` , the
209
211
default ` PHP_EOL ` will be used instead.
210
-
211
- * ** object.method** : < ; boolean> ; (true)
212
+
213
+ * ** object.method** : < ; boolean> ; (true)< br >
212
214
When set to ` true ` , any encoded object will be checked for methods ` toPHP() `
213
215
and ` toPHPValue() ` . If the method ` toPHP() ` exists, the returned string will
214
216
be used as the PHP code representation of the object. If the method
215
217
` toPHPValue() ` exists instead, the returned value will be encoded as PHP and
216
218
used as the code representation of the object.
217
-
218
- * ** object.format** : < ; string> ; ('vars')
219
+
220
+ * ** object.format** : < ; string> ; ('vars')< br >
219
221
Default object encoding format. The possible values are:
220
-
222
+
221
223
* ` string ` casts the object to string and then encodes that string as PHP.
222
224
* ` serialize ` serializes the object and wraps it with ` unserialize() `
223
225
* ` export ` mimics the ` var_export() ` object representation
224
- * ` array ` casts the object to an array and encodes that array
226
+ * ` array ` casts the object to an array and encodes that array
225
227
* ` vars ` turns object into an array using ` get_object_vars() `
226
228
* ` iterate ` turns the object into an array by iterating over it with ` foreach `
227
-
228
- * ** object.cast** : < ; boolean> ; (true)
229
+
230
+ * ** object.cast** : < ; boolean> ; (true)< br >
229
231
Whether to add an ` (object) ` cast in front of arrays generated from objects
230
232
or not when using the object encoding formats ` vars ` , ` array ` or ` iterate ` .
231
-
232
- * ** recursion.detect** : < ; boolean> ; (true)
233
+
234
+ * ** recursion.detect** : < ; boolean> ; (true)< br >
233
235
When set to ` true ` , the encoder will attempt to detect circular references
234
236
in arrays and objects to avoid infinite loops.
235
-
236
- * ** recursion.ignore** : < ; boolean> ; (false)
237
+
238
+ * ** recursion.ignore** : < ; boolean> ; (false)< br >
237
239
When set to ` true ` , any circular reference will be replaced with ` null `
238
240
instead of throwing an exception.
239
-
240
- * ** recursion.max** : < ; integer|false> ; (false)
241
+
242
+ * ** recursion.max** : < ; integer|false> ; (false)< br >
241
243
Maximum number of levels when encoding arrays and objects. Exception is
242
244
thrown when the maximum is exceeded. Set to ` false ` to have no limit.
243
245
0 commit comments