@@ -60,13 +60,13 @@ public static function fromHttpValue(string $httpValue): self
60
60
[$ value , $ parameters ] = match (true ) {
61
61
$ httpValue === '' ,
62
62
1 === preg_match ("/[ \r\t\n]/ " , $ httpValue ),
63
- 1 === preg_match ("/[^ \x20- \x7E]/ " , $ httpValue ) => throw new SyntaxError ("Item field `$ httpValue` contains invalid characters. " ),
63
+ 1 === preg_match ("/[^ \x20- \x7E]/ " , $ httpValue ) => throw new SyntaxError ("The HTTP textual representation `$ httpValue` for an item contains invalid characters. " ),
64
64
1 === preg_match ('/^(-?[0-9])/ ' , $ httpValue ) => self ::parseNumber ($ httpValue ),
65
65
$ httpValue [0 ] == '" ' => self ::parseString ($ httpValue ),
66
66
$ httpValue [0 ] == ': ' => self ::parseBytesSequence ($ httpValue ),
67
67
$ httpValue [0 ] == '? ' => self ::parseBoolean ($ httpValue ),
68
68
1 === preg_match ('/^([a-z*])/i ' , $ httpValue ) => self ::parseToken ($ httpValue ),
69
- default => throw new SyntaxError ("Item field `$ httpValue` is unknown or unsupported. " ),
69
+ default => throw new SyntaxError ("The HTTP textual representation `$ httpValue` for an item is unknown or unsupported. " ),
70
70
};
71
71
72
72
return new self ($ value , Parameters::fromHttpValue ($ parameters ));
@@ -83,7 +83,7 @@ private static function parseToken(string $string): array
83
83
}
84
84
85
85
if (1 !== preg_match ('/ ' .$ regexp .'/i ' , $ string , $ matches )) {
86
- throw new SyntaxError ("The token item ` $ string` contains invalid characters. " );
86
+ throw new SyntaxError ("The HTTP textual representation ` $ string` for a token contains invalid characters. " );
87
87
}
88
88
89
89
return [
@@ -98,7 +98,7 @@ private static function parseToken(string $string): array
98
98
private static function parseBoolean (string $ string ): array
99
99
{
100
100
if (1 !== preg_match ('/^\?[01]/ ' , $ string )) {
101
- throw new SyntaxError (' The boolean item ` ' . $ string. ' ` contains invalid characters.' );
101
+ throw new SyntaxError (" The HTTP textual representation ` $ string` for a boolean contains invalid characters." );
102
102
}
103
103
104
104
return [$ string [1 ] === '1 ' , substr ($ string , 2 )];
@@ -110,7 +110,7 @@ private static function parseBoolean(string $string): array
110
110
private static function parseBytesSequence (string $ string ): array
111
111
{
112
112
if (1 !== preg_match ('/^:(?<bytes>[a-z0-9+\/=]*):/i ' , $ string , $ matches )) {
113
- throw new SyntaxError (' The byte sequence item ` ' . $ string. ' ` contains invalid characters.' );
113
+ throw new SyntaxError (" The HTTP textual representation ` $ string` for a byte sequence contains invalid characters." );
114
114
}
115
115
116
116
return [ByteSequence::fromEncoded ($ matches ['bytes ' ]), substr ($ string , strlen ($ matches [0 ]))];
@@ -122,13 +122,13 @@ private static function parseBytesSequence(string $string): array
122
122
private static function parseNumber (string $ string ): array
123
123
{
124
124
if (1 !== preg_match ('/^(?<number>-?\d+(?:\.\d+)?)(?:[^\d.]|$)/ ' , $ string , $ found )) {
125
- throw new SyntaxError (' The number item ` ' . $ string. ' ` contains invalid format. ' );
125
+ throw new SyntaxError (" The HTTP textual representation ` $ string` for a number contains invalid characters. " );
126
126
}
127
127
128
128
$ number = match (true ) {
129
129
1 === preg_match ('/^-?\d{1,12}\.\d{1,3}$/ ' , $ found ['number ' ]) => (float ) $ found ['number ' ],
130
130
1 === preg_match ('/^-?\d{1,15}$/ ' , $ found ['number ' ]) => (int ) $ found ['number ' ],
131
- default => throw new SyntaxError (' The number item ` ' . $ string. ' ` contains too many digits' ),
131
+ default => throw new SyntaxError (" The HTTP textual representation ` $ string` for a number contain too many digits. " ),
132
132
};
133
133
134
134
return [$ number , substr ($ string , strlen ($ found ['number ' ]))];
@@ -157,19 +157,19 @@ private static function parseString(string $string): array
157
157
}
158
158
159
159
if ($ string === '' ) {
160
- throw new SyntaxError (' Invalid end of string' );
160
+ throw new SyntaxError (" The HTTP textual representation ` $ originalString ` for a string contains an invalid end string. " );
161
161
}
162
162
163
163
$ char = $ string [0 ];
164
164
$ string = substr ($ string , 1 );
165
165
if (!in_array ($ char , ['" ' , '\\' ], true )) {
166
- throw new SyntaxError (' Invalid escaped character in string ` ' . $ originalString. ' ` ' );
166
+ throw new SyntaxError (" The HTTP textual representation ` $ originalString` for a string contains invalid characters. " );
167
167
}
168
168
169
169
$ returnValue .= $ char ;
170
170
}
171
171
172
- throw new SyntaxError (' Invalid end of string' );
172
+ throw new SyntaxError (" The HTTP textual representation ` $ originalString ` for a string contains an invalid end string. " );
173
173
}
174
174
175
175
public function value (): Token |ByteSequence |int |float |string |bool
0 commit comments