Skip to content

Commit d626b1e

Browse files
committed
Improve decoupling from Parser
1 parent cf249e4 commit d626b1e

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,21 @@ echo InnerList::new('foo', 'bar')
529529

530530
### Advanced usages
531531

532-
Starting with version `1.1.0` the parser is made public with the following static methods:
532+
Starting with version `1.1.0` the parser is made public with the following public static methods:
533533

534-
- `Parser::parseList(Stringable|String $value): array`
535-
- `Parser::parseInnerList(Stringable|String $value): array`
536-
- `Parser::parseDictionary(Stringable|String $value): array`
537-
- `Parser::parseItem(Stringable|String $value): array`
538-
- `Parser::parseParameters(Stringable|String $value): array`
534+
```php
535+
Parser::parseList(Stringable|String $value): array
536+
Parser::parseDictionary(Stringable|String $value): array
537+
Parser::parseItem(Stringable|String $value): array
538+
Parser::parseInnerList(Stringable|String $value): array
539+
Parser::parseParameters(Stringable|String $value): array
540+
```
539541

540-
All these static methods parse the HTTP Header string value and return a `array` structure
542+
All these static methods parse the HTTP Header string value and return an `array` structure
541543
representing the parsed string. It is possible to use this representation if you want
542-
to build your own structure field objects. Those methods are the ones used by all the
543-
`fromHttpValue` named constructors to generate `StructuredField` instances from their
544-
returned `array`.
544+
to build your own structure field objects. Those methods are the ones used inside the
545+
respective `fromHttpValue` named constructors to generate `StructuredField` instances
546+
from their returned value.
545547

546548
## Contributing
547549

src/Parser.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function parseItem(Stringable|string $httpValue): array
4848
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item contains invalid characters.');
4949
}
5050

51-
[$value, $offset] = Parser::parseValue($itemString);
51+
[$value, $offset] = Parser::extractValue($itemString);
5252
$remainder = substr($itemString, $offset);
5353
if ('' !== $remainder && !str_contains($remainder, ';')) {
5454
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item contains invalid characters.');
@@ -69,7 +69,7 @@ public static function parseItem(Stringable|string $httpValue): array
6969
public static function parseParameters(Stringable|string $httpValue): array
7070
{
7171
$httpValue = trim((string) $httpValue);
72-
[$parameters, $offset] = Parser::parseParametersValues($httpValue);
72+
[$parameters, $offset] = Parser::extractParametersValues($httpValue);
7373
if (strlen($httpValue) !== $offset) {
7474
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for Parameters contains invalid characters.');
7575
}
@@ -212,7 +212,7 @@ private static function parseInnerListValue(string $httpValue): array
212212

213213
if (')' === $remainder[0]) {
214214
$remainder = substr($remainder, 1);
215-
[$parameters, $offset] = self::parseParametersValues($remainder);
215+
[$parameters, $offset] = self::extractParametersValues($remainder);
216216
$remainder = substr($remainder, $offset);
217217

218218
return [[$list, $parameters], strlen($httpValue) - strlen($remainder)];
@@ -235,9 +235,9 @@ private static function parseInnerListValue(string $httpValue): array
235235
*/
236236
private static function parseItemValue(string $remainder): array
237237
{
238-
[$value, $offset] = self::parseValue($remainder);
238+
[$value, $offset] = self::extractValue($remainder);
239239
$remainder = substr($remainder, $offset);
240-
[$parameters, $offset] = self::parseParametersValues($remainder);
240+
[$parameters, $offset] = self::extractParametersValues($remainder);
241241

242242
return [[$value, $parameters], substr($remainder, $offset)];
243243
}
@@ -249,7 +249,7 @@ private static function parseItemValue(string $remainder): array
249249
*
250250
* @return array{0:SfType, 1:int}
251251
*/
252-
private static function parseValue(string $httpValue): array
252+
private static function extractValue(string $httpValue): array
253253
{
254254
return match (true) {
255255
'"' === $httpValue[0] => self::parseString($httpValue),
@@ -269,7 +269,7 @@ private static function parseValue(string $httpValue): array
269269
*
270270
* @return array{0:array<string, SfType>, 1:int}
271271
*/
272-
private static function parseParametersValues(Stringable|string $httpValue): array
272+
private static function extractParametersValues(Stringable|string $httpValue): array
273273
{
274274
$map = [];
275275
$httpValue = (string) $httpValue;
@@ -284,7 +284,7 @@ private static function parseParametersValues(Stringable|string $httpValue): arr
284284
if ('' !== $remainder && '=' === $remainder[0]) {
285285
$remainder = substr($remainder, 1);
286286

287-
[$map[$key], $offset] = self::parseValue($remainder);
287+
[$map[$key], $offset] = self::extractValue($remainder);
288288
$remainder = substr($remainder, $offset);
289289
}
290290
}

0 commit comments

Comments
 (0)