@@ -29,6 +29,27 @@ private function __construct(
29
29
) {
30
30
}
31
31
32
+ /**
33
+ * Returns a new instance from an HTTP Header or Trailer value string
34
+ * in compliance with RFC8941.
35
+ *
36
+ * @see https://www.rfc-editor.org/rfc/rfc8941.html#section-3.3
37
+ */
38
+ public static function fromHttpValue (Stringable |string $ httpValue ): self
39
+ {
40
+ $ itemString = trim ((string ) $ httpValue , ' ' );
41
+ if ('' === $ itemString || 1 === preg_match ("/[ \r\t\n]|[^ \x20- \x7E]/ " , $ itemString )) {
42
+ throw new SyntaxError ('The HTTP textual representation " ' .$ httpValue .'" for an item contains invalid characters. ' );
43
+ }
44
+
45
+ [$ value , $ offset ] = Parser::parseBareItem ($ itemString );
46
+ if (!str_contains ($ itemString , '; ' ) && $ offset !== strlen ($ itemString )) {
47
+ throw new SyntaxError ('The HTTP textual representation " ' .$ httpValue .'" for an item contains invalid characters. ' );
48
+ }
49
+
50
+ return new self (new Value ($ value ), Parameters::fromHttpValue (substr ($ itemString , $ offset )));
51
+ }
52
+
32
53
/**
33
54
* Returns a new instance from a value type and an iterable of key-value parameters.
34
55
*
@@ -69,24 +90,11 @@ public static function fromPair(array $pair): self
69
90
}
70
91
71
92
/**
72
- * Returns a new instance from an HTTP Header or Trailer value string
73
- * in compliance with RFC8941.
74
- *
75
- * @see https://www.rfc-editor.org/rfc/rfc8941.html#section-3.3
93
+ * Returns a new bare instance from value.
76
94
*/
77
- public static function fromHttpValue ( Stringable | string $ httpValue ): self
95
+ private static function fromValue ( Value $ value ): self
78
96
{
79
- $ itemString = trim ((string ) $ httpValue , ' ' );
80
- if ('' === $ itemString || 1 === preg_match ("/[ \r\t\n]|[^ \x20- \x7E]/ " , $ itemString )) {
81
- throw new SyntaxError ('The HTTP textual representation " ' .$ httpValue .'" for an item contains invalid characters. ' );
82
- }
83
-
84
- [$ value , $ offset ] = Parser::parseBareItem ($ itemString );
85
- if (!str_contains ($ itemString , '; ' ) && $ offset !== strlen ($ itemString )) {
86
- throw new SyntaxError ('The HTTP textual representation " ' .$ httpValue .'" for an item contains invalid characters. ' );
87
- }
88
-
89
- return new self (new Value ($ value ), Parameters::fromHttpValue (substr ($ itemString , $ offset )));
97
+ return new self ($ value , Parameters::create ());
90
98
}
91
99
92
100
/**
@@ -97,14 +105,6 @@ public static function fromEncodedByteSequence(Stringable|string $value): self
97
105
return self ::fromValue (Value::fromEncodedByteSequence ($ value ));
98
106
}
99
107
100
- /**
101
- * Returns a new bare instance from value.
102
- */
103
- private static function fromValue (Value $ value ): self
104
- {
105
- return new self ($ value , Parameters::create ());
106
- }
107
-
108
108
/**
109
109
* Returns a new instance from a decoded byte sequence and an iterable of key-value parameters.
110
110
*/
@@ -219,11 +219,6 @@ public function parameter(string $key): mixed
219
219
}
220
220
}
221
221
222
- public function __toString (): string
223
- {
224
- return $ this ->toHttpValue ();
225
- }
226
-
227
222
/**
228
223
* Serialize the Item value according to RFC8941.
229
224
*
@@ -234,6 +229,11 @@ public function toHttpValue(): string
234
229
return $ this ->value ->serialize ().$ this ->parameters ->toHttpValue ();
235
230
}
236
231
232
+ public function __toString (): string
233
+ {
234
+ return $ this ->toHttpValue ();
235
+ }
236
+
237
237
/**
238
238
* @return array{0:SfItemInput, 1:MemberOrderedMap<string, SfItem>}
239
239
*/
0 commit comments