@@ -20,21 +20,32 @@ If we go back to our permission policy field example:
20
20
$headerLine = 'picture-in-picture=(), geolocation=(self "https://example.com/"), camera=*';
21
21
//the raw header line is a structured field dictionary
22
22
$permissions = Dictionary::fromHttpValue($headerLine); // parse the field
23
- ```
24
-
25
- The following methods are available, for all containers:
26
-
27
- ``` php
28
23
$permissions->indices(); // returns [0, 1, 2]
29
- $permissions->hasIndices(-2); // returns true bacause negative index are supported
24
+ $permissions->hasIndices(-2); // returns true because negative index are supported
30
25
$permissions->getByIndex(1); // returns ['geolocation', InnerList::new(Token::fromString('self'), "https://example.com/")]
26
+ $permissions['geolocation']; // returns InnerList::new(Token::fromString('self'), "https://example.com/")
27
+ $permissions[1]; // throws a TypeError only string are allowed for Dictionary and Parameters
31
28
$permissions->isNotEmpty():; // returns true
32
29
$permissions->isEmpty(); // returns false
33
30
```
34
31
35
32
> [ !IMPORTANT]
36
33
> The ` getByIndex ` method will throw an ` InvalidOffset ` exception if no member exists for the given ` $offset ` .
37
34
35
+ Here's an example with a ` List ` container:
36
+
37
+ ``` php
38
+ $headerLine = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8'
39
+ $accepts = OuterList::fromHttpValue($headerLine); // parse the field
40
+ $accepts->indices(); // returns [0, 1, 2, 3, 4]
41
+ $accepts->hasIndices(-2); // returns true because negative index are supported
42
+ $accepts->getByIndex(1); // returns Token::fromString('application/xhtml+xml')
43
+ $accepts[1]; // returns Token::fromString('application/xhtml+xml')
44
+ $accepts['foo']; // throws a TypeError only integer are allowed for List and InnerList
45
+ $permissions->isNotEmpty():; // returns true
46
+ $permissions->isEmpty(); // returns false
47
+ ```
48
+
38
49
> [ !IMPORTANT]
39
50
> For ordered maps, the ` getByIndex ` method returns a list containing exactly 2 entries.
40
51
> The first entry is the member name, the second entry is the member value.
@@ -76,8 +87,8 @@ $permissions->indexByName('geolocation'): // returns 1
76
87
> The ` getByName ` method will throw an ` InvalidOffset ` exception if no member exists for the given ` $offset ` .
77
88
78
89
> [ !TIP]
79
- > The ` ArrayAccess ` interface proxy the result from ` getByIndex ` in list .
80
- > The ` ArrayAccess ` interface proxy the result from ` getByName ` in ordered map .
90
+ > The ` ArrayAccess ` interface proxy the result from ` getByIndex ` with ` OuterList ` and ` InnerList ` .
91
+ > The ` ArrayAccess ` interface proxy the result from ` getByName ` with ` Dictionary ` and ` Parameters ` .
81
92
82
93
### Accessing the parameters values
83
94
@@ -92,9 +103,9 @@ parameter.
92
103
> The ` parameterByName ` proxy the result from ` valueByName ` .
93
104
> The ` parameterByIndex ` proxy the result from ` valueByIndex ` .
94
105
95
- ## Building and Updating Structured Fields Values
106
+ ## Building and Updating COntainers
96
107
97
- Every value object can be used as a builder to create an HTTP field value. Because we are
108
+ Every container can be used as a builder to create an HTTP field value. Because we are
98
109
using immutable value objects any change to the value object will return a new instance
99
110
with the changes applied and leave the original instance unchanged.
100
111
@@ -116,7 +127,7 @@ echo $value->toHttpValue(); //"b=?0, a=bar, c=@1671800423"
116
127
echo $value; //"b=?0, a=bar, c=@1671800423"
117
128
```
118
129
119
- or using their indices with an iterable structure of pairs (tuple) as defined in the RFC:
130
+ or using their indices with an iterable structure of pairs as defined in the RFC:
120
131
121
132
``` php
122
133
use Bakame\Http\StructuredFields\Parameters;
@@ -225,8 +236,8 @@ echo $field->removeByNames('expire', 'httponly', 'max-age')->toHttpValue(); // r
225
236
226
237
### Automatic conversion
227
238
228
- For all containers, to ease instantiation the following automatic conversion are applied on
229
- the member argument of each modifying methods.
239
+ Learning new types may be a daunting tasks so for ease of usage, for all containers, the following automatic
240
+ conversion are applied on the member argument of each modifying methods.
230
241
231
242
If the submitted type is:
232
243
@@ -384,21 +395,20 @@ Both objects provide additional modifying methods to help deal with parameters.
384
395
You can attach and update the associated ` Parameters ` instance using the following methods.
385
396
386
397
``` php
398
+ $field->withParameters(Parameters $parameters): static;
387
399
$field->addParameter(string $name, mixed $value): static;
388
400
$field->appendParameter(string $name, mixed $value): static;
389
401
$field->prependParameter(string $name, mixed $value): static;
390
- $field->withoutParametersByNames(string ...$names): static;
391
- $field->withoutAnyParameter(): static;
392
- $field->withParameters(Parameters $parameters): static;
393
402
$field->pushParameters(array ...$pairs): static
394
403
$field->unshiftParameters(array ...$pairs): static
395
404
$field->insertParameters(int $index, array ...$pairs): static
396
405
$field->replaceParameter(int $index, array $pair): static
397
406
$field->withoutParametersByNames(string ...$names): static
398
407
$field->withoutParametersByIndices(int ...$indices): static
408
+ $field->withoutAnyParameter(): static;
399
409
```
400
410
401
- The ` $pair ` parameter is a tuple (ie: an array as list with exactly two members) where:
411
+ The ` $pair ` parameter is an array as list with exactly two members where:
402
412
403
413
- the first array member is the parameter ` $name `
404
414
- the second array member is the parameter ` $value `
0 commit comments