@@ -63,6 +63,8 @@ header. Content validation is out of scope for this library.**
63
63
64
64
### Parsing and Serializing Structured Fields
65
65
66
+ #### Basic usage
67
+
66
68
Parsing the header value is done via the ` fromHttpValue ` named constructor.
67
69
The method is attached to each library's structured fields representation
68
70
as shown below:
@@ -115,14 +117,27 @@ All five (5) structured data type as defined in the RFC are provided inside the
115
117
116
118
#### Advance usage
117
119
118
- In order to allow:
120
+ Starting with version ` 1.1 ` the internal parser has been made public in order to allow:
119
121
120
122
- clearer decoupling betwen parsing and objet building
121
123
- different parsers implementations
122
124
- improve the package usage in testing.
123
125
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
+ Each ` fromHttpValue ` method signature has been updated to take a second optional argument
127
+ that represents the parser interface to use in order to allow parsing of the HTTP string
128
+ representation value.
129
+
130
+ By default, if no parser is provided, the package will default to use the package ` Parser ` class,
131
+
132
+ ``` php
133
+ Item::fromHttpValue(Stringable|string $httpValue, ItemParser $parser = new Parser()): Item;
134
+ InnerList::fromHttpValue(Stringable|string $httpValue, InnerListParser $parser = new Parser()): InnerList;
135
+ Dictionary::fromHttpValue(Stringable|string $httpValue, DictionaryParser $parser = new Parser()): Dictionary;
136
+ OuterList::fromHttpValue(Stringable|string $httpValue, ListParser $parser = new Parser()): OuterList;
137
+ Parameters::fromHttpValue(Stringable|string $httpValue, ParametersParser $parser = new Parser()): Parameters;
138
+ ```
139
+
140
+ The ` Parser ` class exposes the following method each belonging to a different contract or interface.
126
141
127
142
``` php
128
143
Parser::parseValue(Stringable|string $httpValue): ByteSequence|Token|DateTimeImmutable|string|int|float|bool;
@@ -133,8 +148,7 @@ Parser::parseList(Stringable|string $httpValue): array;
133
148
Parser::parseDictionary(Stringable|string $httpValue): array;
134
149
```
135
150
136
- While the provided default ` Parser ` class implements all these methods
137
- you are free to only implement the methods you need.
151
+ Once instantiated, calling one of the above listed method is straightforward:
138
152
139
153
``` php
140
154
use Bakame\Http\StructuredFields\Parser;
@@ -149,19 +163,8 @@ $parser->parseItem('@1234567890;file=24');
149
163
// ]
150
164
```
151
165
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
- ```
166
+ ** While the provided default ` Parser ` class implements all these methods you are free to only implement
167
+ the methods you need.**
165
168
166
169
### Accessing Structured Fields Values
167
170
@@ -406,7 +409,7 @@ $map->append(string $key, $value): static;
406
409
$map->prepend(string $key, $value): static;
407
410
$map->mergeAssociative(...$others): static;
408
411
$map->mergePairs(...$others): static;
409
- $map->remove(string ...$key): static;
412
+ $map->remove(string|int ...$key): static;
410
413
```
411
414
412
415
As shown below:
@@ -474,6 +477,19 @@ echo $value; //b=?0, a=(bar "42" 42 42.0), c=@1671800423
474
477
475
478
** ⚠️WARNING: on duplicate ` keys ` pair values are merged as per RFC logic.**
476
479
480
+ The ` remove ` always accepted string or integer as input. Since version ` 1.1 ` it will also remove
481
+ the corresponding pair if its index is given to the method.
482
+
483
+ ``` diff
484
+ <?php
485
+
486
+ use Bakame\Http\StructuredFields\Dictionary;
487
+
488
+ $field = Dictionary::fromHttpValue('b=?0, a=(bar "42" 42 42.0), c=@1671800423');
489
+ - echo $field->remove('b', 2)->toHttpValue(); // returns a=(bar "42" 42 42.0), c=@1671800423
490
+ + echo $field->remove('b', 2)->toHttpValue(); // returns a=(bar "42" 42 42.0)
491
+ ```
492
+
477
493
#### Automatic conversion
478
494
479
495
For all containers, to ease instantiation the following automatic conversion are applied on
0 commit comments