@@ -113,6 +113,56 @@ All five (5) structured data type as defined in the RFC are provided inside the
113113- ` OuterList ` (named ` List ` in the RFC but renamed in the package because ` list ` is a reserved word in PHP.)
114114- ` InnerList `
115115
116+ #### Advance usage
117+
118+ In order to allow:
119+
120+ - clearer decoupling betwen parsing and objet building
121+ - different parsers implementations
122+ - improve the package usage in testing.
123+
124+ Starting with version ` 1.1 ` the internal parser has been made public. The class exposes
125+ the following method each belonging to a different contract or interface.
126+
127+ ``` php
128+ Parser::parseValue(Stringable|string $httpValue): ByteSequence|Token|DateTimeImmutable|string|int|float|bool;
129+ Parser::parseItem(Stringable|string $httpValue): array;
130+ Parser::parseParameters(Stringable|string $httpValue): array;
131+ Parser::parseInnerList(Stringable|string $httpValue): array;
132+ Parser::parseList(Stringable|string $httpValue): array;
133+ Parser::parseDictionary(Stringable|string $httpValue): array;
134+ ```
135+
136+ While the provided default ` Parser ` class implements all these methods
137+ you are free to only implement the methods you need.
138+
139+ ``` php
140+ use Bakame\Http\StructuredFields\Parser;
141+
142+ $parser = new Parser();
143+ $parser->parseValue('text/csv'); //returns Token::fromString('text/csv')
144+ $parser->parseItem('@1234567890;file=24');
145+ //returns an array
146+ // [
147+ // new DateTimeImmutable('@1234567890'),
148+ // ['file' => 24],
149+ // ]
150+ ```
151+
152+ Each ` fromHttpValue ` method signature has been updated to take a second optional argument
153+ that represents the parser interface to use in order to allow parsing of the HTTP string
154+ representation value.
155+
156+ By default, if no parser is provided, the package will default to use the package ` Parser ` class,
157+
158+ ``` php
159+ Item::fromHttpValue(Stringable|string $httpValue, ItemParser $parser = new Parser()): Item;
160+ InnerList::fromHttpValue(Stringable|string $httpValue, InnerListParser $parser = new Parser()): InnerList;
161+ Dictionary::fromHttpValue(Stringable|string $httpValue, DictionaryParser $parser = new Parser()): Dictionary;
162+ OuterList::fromHttpValue(Stringable|string $httpValue, ListParser $parser = new Parser()): OuterList;
163+ Parameters::fromHttpValue(Stringable|string $httpValue, ParametersParser $parser = new Parser()): Parameters;
164+ ```
165+
116166### Accessing Structured Fields Values
117167
118168#### RFC Value type
0 commit comments