@@ -103,7 +103,7 @@ public static function fromHttpValue(string $httpValue): self
103
103
{
104
104
$ httpValue = trim ($ httpValue , ' ' );
105
105
[$ value , $ parameters ] = match (true ) {
106
- $ httpValue === '' ,
106
+ '' === $ httpValue ,
107
107
1 === preg_match ("/[ \r\t\n]/ " , $ httpValue ),
108
108
1 === preg_match ("/[^ \x20- \x7E]/ " , $ httpValue ) => throw new SyntaxError ("The HTTP textual representation ` $ httpValue` for an item contains invalid characters. " ),
109
109
1 === preg_match ('/^(-?[0-9])/ ' , $ httpValue ) => self ::parseNumber ($ httpValue ),
@@ -225,26 +225,21 @@ private static function parseString(string $string): array
225
225
throw new SyntaxError ("The HTTP textual representation ` $ originalString` for a string contains an invalid end string. " );
226
226
}
227
227
228
- public function toHttpValue (): string
229
- {
230
- return $ this ->serializeValue ($ this ->value ).$ this ->parameters ->toHttpValue ();
231
- }
232
-
233
228
/**
234
229
* Serialize the Item value according to RFC8941.
235
230
*
236
231
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.1
237
232
*/
238
- private function serializeValue ( Token | ByteSequence | int | float | string | bool $ value ): string
233
+ public function toHttpValue ( ): string
239
234
{
240
235
return match (true ) {
241
- $ value instanceof Token => $ value -> toHttpValue () ,
242
- $ value instanceof ByteSequence => $ value -> toHttpValue () ,
243
- is_string ( $ value ) => ' " ' . preg_replace ( ' /([" \\ \])/ ' , '\\ \$1 ' , $ value ). ' " ' ,
244
- is_int ( $ value ) => ( string ) $ value ,
245
- is_float ( $ value ) => $ this ->serializeDecimal ( $ value ),
246
- default => ' ? ' .( $ value ? ' 1 ' : ' 0 ' ),
247
- } ;
236
+ is_string ( $ this -> value ) => ' " ' . preg_replace ( ' /([" \\ \])/ ' , '\\ \$1 ' , $ this -> value ). ' " ' ,
237
+ is_int ( $ this -> value ) => ( string ) $ this -> value ,
238
+ is_float ( $ this -> value ) => $ this -> serializeDecimal ( $ this -> value ),
239
+ is_bool ( $ this -> value ) => ' ? ' .( $ this -> value ? ' 1 ' : ' 0 ' ) ,
240
+ default => $ this ->value -> toHttpValue ( ),
241
+ }
242
+ . $ this -> parameters -> toHttpValue () ;
248
243
}
249
244
250
245
/**
0 commit comments