25
25
final class Parser
26
26
{
27
27
/**
28
- * Returns an OrderedList value object from an HTTP textual representation.
28
+ * Returns an ordered list represented as a PHP list array from an HTTP textual representation.
29
29
*
30
30
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1
31
31
*
@@ -36,18 +36,18 @@ final class Parser
36
36
*/
37
37
public static function parseList (string $ httpValue ): array
38
38
{
39
- $ members = [];
39
+ $ list = [];
40
40
$ remainder = ltrim ($ httpValue , ' ' );
41
41
while ('' !== $ remainder ) {
42
- [$ members [], $ offset ] = self ::parseItemOrInnerList ($ remainder );
42
+ [$ list [], $ offset ] = self ::parseItemOrInnerList ($ remainder );
43
43
$ remainder = self ::removeCommaSeparatedWhiteSpaces ($ remainder , $ offset );
44
44
}
45
45
46
- return $ members ;
46
+ return $ list ;
47
47
}
48
48
49
49
/**
50
- * Returns a Dictionary value object from an HTTP textual representation.
50
+ * Returns an ordered map represented as a PHP associative array from an HTTP textual representation.
51
51
*
52
52
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.2
53
53
*
@@ -58,7 +58,7 @@ public static function parseList(string $httpValue): array
58
58
*/
59
59
public static function parseDictionary (string $ httpValue ): array
60
60
{
61
- $ members = [];
61
+ $ map = [];
62
62
$ remainder = ltrim ($ httpValue , ' ' );
63
63
while ('' !== $ remainder ) {
64
64
[$ key , $ offset ] = self ::parseKey ($ remainder );
@@ -67,15 +67,15 @@ public static function parseDictionary(string $httpValue): array
67
67
$ remainder = '=?1 ' .$ remainder ;
68
68
}
69
69
70
- [$ members [$ key ], $ offset ] = self ::parseItemOrInnerList (substr ($ remainder , 1 ));
70
+ [$ map [$ key ], $ offset ] = self ::parseItemOrInnerList (substr ($ remainder , 1 ));
71
71
$ remainder = self ::removeCommaSeparatedWhiteSpaces ($ remainder , ++$ offset );
72
72
}
73
73
74
- return $ members ;
74
+ return $ map ;
75
75
}
76
76
77
77
/**
78
- * Returns a InnerList value object from an HTTP textual representation.
78
+ * Returns an inner list represented as a PHP list array from an HTTP textual representation.
79
79
*
80
80
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.2
81
81
*
@@ -91,52 +91,52 @@ public static function parseInnerList(string $httpValue): array
91
91
throw new SyntaxError ("The HTTP textual representation ` $ httpValue` for a inner list is missing a parenthesis. " );
92
92
}
93
93
94
- [$ members , $ offset ] = self ::parseInnerListValue ($ remainder );
94
+ [$ list , $ offset ] = self ::parseInnerListValue ($ remainder );
95
95
$ remainder = self ::removeOptionalWhiteSpaces (substr ($ remainder , $ offset ));
96
96
97
97
if ('' !== $ remainder ) {
98
98
throw new SyntaxError ("The HTTP textual representation ` $ httpValue` for a inner list contains invalid data. " );
99
99
}
100
100
101
- return $ members ;
101
+ return $ list ;
102
102
}
103
103
104
104
/**
105
105
* Filter optional white spaces before and after comma.
106
106
*
107
107
* @see https://tools.ietf.org/html/rfc7230#section-3.2.3
108
108
*/
109
- private static function removeCommaSeparatedWhiteSpaces (string $ remainder , int $ offset ): string
109
+ private static function removeCommaSeparatedWhiteSpaces (string $ httpValue , int $ offset ): string
110
110
{
111
- $ remainder = self ::removeOptionalWhiteSpaces (substr ($ remainder , $ offset ));
112
- if ('' === $ remainder ) {
113
- return $ remainder ;
111
+ $ httpValue = self ::removeOptionalWhiteSpaces (substr ($ httpValue , $ offset ));
112
+ if ('' === $ httpValue ) {
113
+ return $ httpValue ;
114
114
}
115
115
116
- if (1 !== preg_match ('/^(?<space>,[ \t]*)/ ' , $ remainder , $ found )) {
116
+ if (1 !== preg_match ('/^(?<space>,[ \t]*)/ ' , $ httpValue , $ found )) {
117
117
throw new SyntaxError ('The HTTP textual representation is missing an excepted comma. ' );
118
118
}
119
119
120
- $ remainder = substr ($ remainder , strlen ($ found ['space ' ]));
121
- if ('' === $ remainder ) {
120
+ $ httpValue = substr ($ httpValue , strlen ($ found ['space ' ]));
121
+ if ('' === $ httpValue ) {
122
122
throw new SyntaxError ('Unexpected end of line for The HTTP textual representation. ' );
123
123
}
124
124
125
- return $ remainder ;
125
+ return $ httpValue ;
126
126
}
127
127
128
128
/**
129
129
* Remove optional white spaces before field value.
130
130
*
131
131
* @see https://tools.ietf.org/html/rfc7230#section-3.2.3
132
132
*/
133
- private static function removeOptionalWhiteSpaces (string $ value ): string
133
+ private static function removeOptionalWhiteSpaces (string $ httpValue ): string
134
134
{
135
- return ltrim ($ value , " \t" );
135
+ return ltrim ($ httpValue , " \t" );
136
136
}
137
137
138
138
/**
139
- * Returns an Item or an InnerList value object from an HTTP textual representation.
139
+ * Returns an Item value object or an inner list as a PHP list array from an HTTP textual representation.
140
140
*
141
141
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.1
142
142
*
@@ -161,7 +161,7 @@ private static function parseItemOrInnerList(string $httpValue): array
161
161
}
162
162
163
163
/**
164
- * Returns an InnerList value object from an HTTP textual representation and the consumed offset.
164
+ * Returns an inner list represented as a PHP list array from an HTTP textual representation and the consumed offset in a tuple .
165
165
*
166
166
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.2
167
167
*
@@ -172,7 +172,7 @@ private static function parseItemOrInnerList(string $httpValue): array
172
172
*/
173
173
private static function parseInnerListValue (string $ httpValue ): array
174
174
{
175
- $ members = [];
175
+ $ list = [];
176
176
$ remainder = substr ($ httpValue , 1 );
177
177
while ('' !== $ remainder ) {
178
178
$ remainder = ltrim ($ remainder , ' ' );
@@ -182,7 +182,7 @@ private static function parseInnerListValue(string $httpValue): array
182
182
[$ parameters , $ offset ] = self ::parseParameters ($ remainder );
183
183
$ remainder = substr ($ remainder , $ offset );
184
184
185
- return [[$ members , $ parameters ], strlen ($ httpValue ) - strlen ($ remainder )];
185
+ return [[$ list , $ parameters ], strlen ($ httpValue ) - strlen ($ remainder )];
186
186
}
187
187
188
188
[$ value , $ offset ] = self ::parseBareItem ($ remainder );
@@ -191,7 +191,7 @@ private static function parseInnerListValue(string $httpValue): array
191
191
[$ parameters , $ offset ] = self ::parseParameters ($ remainder );
192
192
$ remainder = substr ($ remainder , $ offset );
193
193
194
- $ members [] = Item::from ($ value , $ parameters );
194
+ $ list [] = Item::from ($ value , $ parameters );
195
195
196
196
if ('' !== $ remainder && !in_array ($ remainder [0 ], [' ' , ') ' ], true )) {
197
197
throw new SyntaxError ("The HTTP textual representation ` $ remainder` for a inner list is using invalid characters. " );
@@ -202,7 +202,7 @@ private static function parseInnerListValue(string $httpValue): array
202
202
}
203
203
204
204
/**
205
- * Returns a Item or an InnerList value object from an HTTP textual representation.
205
+ * Returns an Item value from an HTTP textual representation and the consumed offset in a tuple .
206
206
*
207
207
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.3.1
208
208
*
@@ -222,36 +222,36 @@ private static function parseBareItem(string $httpValue): array
222
222
}
223
223
224
224
/**
225
- * Returns a Parameters value object from an HTTP textual representation.
225
+ * Returns an parameters container represented as a PHP associative array from an HTTP textual representation and the consumed offset in a tuple .
226
226
*
227
227
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.3.2
228
228
*
229
- * @return array{0:array<array-key , Token|ByteSequence|float|int|bool|string>, 1:int}
229
+ * @return array{0:array<string , Token|ByteSequence|float|int|bool|string>, 1:int}
230
230
*/
231
231
private static function parseParameters (string $ httpValue ): array
232
232
{
233
- $ parameters = [];
233
+ $ map = [];
234
234
$ remainder = $ httpValue ;
235
235
while ('' !== $ remainder && '; ' === $ remainder [0 ]) {
236
236
$ remainder = ltrim (substr ($ remainder , 1 ), ' ' );
237
237
238
238
[$ key , $ keyOffset ] = self ::parseKey ($ remainder );
239
- $ parameters [$ key ] = true ;
239
+ $ map [$ key ] = true ;
240
240
241
241
$ remainder = substr ($ remainder , $ keyOffset );
242
242
if ('' !== $ remainder && '= ' === $ remainder [0 ]) {
243
243
$ remainder = substr ($ remainder , 1 );
244
244
245
- [$ parameters [$ key ], $ offset ] = self ::parseBareItem ($ remainder );
245
+ [$ map [$ key ], $ offset ] = self ::parseBareItem ($ remainder );
246
246
$ remainder = substr ($ remainder , $ offset );
247
247
}
248
248
}
249
249
250
- return [$ parameters , strlen ($ httpValue ) - strlen ($ remainder )];
250
+ return [$ map , strlen ($ httpValue ) - strlen ($ remainder )];
251
251
}
252
252
253
253
/**
254
- * Returns a Dictionary or a Parameter string key from an HTTP textual representation.
254
+ * Returns a Dictionary or a Parameter string key from an HTTP textual representation and the consumed offset in a tuple .
255
255
*
256
256
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.3.3
257
257
*
@@ -267,7 +267,7 @@ private static function parseKey(string $httpValue): array
267
267
}
268
268
269
269
/**
270
- * Returns a boolean from an HTTP textual representation.
270
+ * Returns a boolean from an HTTP textual representation and the consumed offset in a tuple .
271
271
*
272
272
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.8
273
273
*
@@ -283,7 +283,7 @@ private static function parseBoolean(string $httpValue): array
283
283
}
284
284
285
285
/**
286
- * Returns a int or a float from an HTTP textual representation.
286
+ * Returns a int or a float from an HTTP textual representation and the consumed offset in a tuple .
287
287
*
288
288
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.4
289
289
*
@@ -301,7 +301,7 @@ private static function parseNumber(string $httpValue): array
301
301
}
302
302
303
303
/**
304
- * Returns a string from an HTTP textual representation.
304
+ * Returns a string from an HTTP textual representation and the consumed offset in a tuple .
305
305
*
306
306
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.5
307
307
*
@@ -345,7 +345,7 @@ private static function parseString(string $httpValue): array
345
345
}
346
346
347
347
/**
348
- * Returns a Token from an HTTP textual representation.
348
+ * Returns a Token from an HTTP textual representation and the consumed offset in a tuple .
349
349
*
350
350
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.6
351
351
*
@@ -359,7 +359,7 @@ private static function parseToken(string $httpValue): array
359
359
}
360
360
361
361
/**
362
- * Returns a Byte Sequence from an HTTP textual representation.
362
+ * Returns a Byte Sequence from an HTTP textual representation and the consumed offset in a tuple .
363
363
*
364
364
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.7
365
365
*
0 commit comments