5
5
namespace Bakame \Http \StructuredFields ;
6
6
7
7
use DateTimeImmutable ;
8
- use DateTimeZone ;
9
8
use Stringable ;
10
9
use function in_array ;
11
10
use function ltrim ;
25
24
* @internal Use Dictionary::fromHttpValue(), Parameters::fromHttpValue(),
26
25
* OuterList::fromHttpValue(), InnerList::fromHttpValue() or Item::fromHttpValue() instead
27
26
*
28
- * @phpstan-import-type SfTypeInput from StructuredField
27
+ * @phpstan-import-type SfType from StructuredField
29
28
* @phpstan-import-type SfItem from StructuredField
30
29
* @phpstan-import-type SfItemInput from StructuredField
31
30
*/
@@ -36,7 +35,7 @@ final class Parser
36
35
*
37
36
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1
38
37
*
39
- * @return array<SfItemInput |array{0:array<SfItemInput> , 1:array<string, SfItemInput >}>
38
+ * @return array<array{0:SfType |array<array {0:SfType, 1: array<string, SfType>}> , 1:array<string, SfType >}>
40
39
*/
41
40
public static function parseList (Stringable |string $ httpValue ): array
42
41
{
@@ -55,7 +54,7 @@ public static function parseList(Stringable|string $httpValue): array
55
54
*
56
55
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.2
57
56
*
58
- * @return array<string, SfItemInput |array{0:array<SfItemInput> , 1:array<string,SfItemInput >}>
57
+ * @return array<string, array{0:SfType |array<array {0:SfType, 1: array<string, SfType>}> , 1:array<string, SfType >}>
59
58
*/
60
59
public static function parseDictionary (Stringable |string $ httpValue ): array
61
60
{
@@ -80,7 +79,7 @@ public static function parseDictionary(Stringable|string $httpValue): array
80
79
*
81
80
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.2
82
81
*
83
- * @return array{0:array<SfItemInput> , 1:array<string, SfItemInput >}
82
+ * @return array{0:array<array{0:SfType, 1:array<string, SfType>}> , 1:array<string, SfType >}
84
83
*/
85
84
public static function parseInnerList (Stringable |string $ httpValue ): array
86
85
{
@@ -137,7 +136,7 @@ private static function removeOptionalWhiteSpaces(string $httpValue): string
137
136
*
138
137
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.1
139
138
*
140
- * @return array{0:array{0:array<SfItemInput> , 1:array<string,SfItemInput>}|SfItem , 1:int}
139
+ * @return array{0:array{0:SfType| array<array{0:SfType, 1:array<string, SfType>}> , 1:array<string, SfType>} , 1:int}
141
140
*/
142
141
private static function parseItemOrInnerList (string $ httpValue ): array
143
142
{
@@ -155,7 +154,7 @@ private static function parseItemOrInnerList(string $httpValue): array
155
154
*
156
155
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.2
157
156
*
158
- * @return array{0:array{0:array<SfItemInput> , 1:array<string, SfItemInput >}, 1:int}
157
+ * @return array{0:array{0:array<array{0:SfType, 1:array<string, SfType>}> , 1:array<string, SfType >}, 1:int}
159
158
*/
160
159
private static function parseInnerListValue (string $ httpValue ): array
161
160
{
@@ -182,12 +181,24 @@ private static function parseInnerListValue(string $httpValue): array
182
181
throw new SyntaxError ("The HTTP textual representation \"$ remainder \" for a inner list has an unexpected end of line. " );
183
182
}
184
183
184
+ /**
185
+ * @return array{0:array{0:SfType, 1:array<string, SfType>}, 1:string}
186
+ */
187
+ private static function parseItem (string $ remainder ): array
188
+ {
189
+ [$ value , $ offset ] = self ::parseBareItem ($ remainder );
190
+ $ remainder = substr ($ remainder , $ offset );
191
+ [$ parameters , $ offset ] = self ::parseParameters ($ remainder );
192
+
193
+ return [[$ value , $ parameters ], substr ($ remainder , $ offset )];
194
+ }
195
+
185
196
/**
186
197
* Returns an Item value from an HTTP textual representation and the consumed offset in a tuple.
187
198
*
188
199
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.3.1
189
200
*
190
- * @return array{0:ByteSequence|Token|DateTimeImmutable|string|int|float|bool , 1:int}
201
+ * @return array{0:SfType , 1:int}
191
202
*/
192
203
public static function parseBareItem (string $ httpValue ): array
193
204
{
@@ -207,7 +218,7 @@ public static function parseBareItem(string $httpValue): array
207
218
*
208
219
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.3.2
209
220
*
210
- * @return array{0:array<string, SfTypeInput >, 1:int}
221
+ * @return array{0:array<string, SfType >, 1:int}
211
222
*/
212
223
public static function parseParameters (string $ httpValue ): array
213
224
{
@@ -280,10 +291,7 @@ private static function parseDate(string $httpValue): array
280
291
throw new SyntaxError ("The HTTP textual representation \"$ httpValue \" for a Date contains invalid characters. " );
281
292
}
282
293
283
- return [
284
- (new DateTimeImmutable ('NOW ' , new DateTimeZone ('UTC ' )))->setTimestamp ((int ) $ found ['date ' ]),
285
- strlen ($ found ['date ' ]) + 1 ,
286
- ];
294
+ return [new DateTimeImmutable ('@ ' .$ found ['date ' ]), strlen ($ found ['date ' ]) + 1 ];
287
295
}
288
296
289
297
/**
@@ -362,16 +370,4 @@ private static function parseByteSequence(string $httpValue): array
362
370
363
371
return [ByteSequence::fromEncoded ($ matches ['byte ' ]), strlen ($ matches ['sequence ' ])];
364
372
}
365
-
366
- /**
367
- * @return array{0:SfItem, 1:string}
368
- */
369
- private static function parseItem (string $ remainder ): array
370
- {
371
- [$ value , $ offset ] = self ::parseBareItem ($ remainder );
372
- $ remainder = substr ($ remainder , $ offset );
373
- [$ parameters , $ offset ] = self ::parseParameters ($ remainder );
374
-
375
- return [Item::fromAssociative ($ value , $ parameters ), substr ($ remainder , $ offset )];
376
- }
377
373
}
0 commit comments