Skip to content

Commit 12f99c3

Browse files
committed
Update documentation v2
1 parent faacc0e commit 12f99c3

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

docs/04-containers.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,32 @@ If we go back to our permission policy field example:
2020
$headerLine = 'picture-in-picture=(), geolocation=(self "https://example.com/"), camera=*';
2121
//the raw header line is a structured field dictionary
2222
$permissions = Dictionary::fromHttpValue($headerLine); // parse the field
23-
```
24-
25-
The following methods are available, for all containers:
26-
27-
```php
2823
$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
3025
$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
3128
$permissions->isNotEmpty():; // returns true
3229
$permissions->isEmpty(); // returns false
3330
```
3431

3532
> [!IMPORTANT]
3633
> The `getByIndex` method will throw an `InvalidOffset` exception if no member exists for the given `$offset`.
3734
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+
3849
> [!IMPORTANT]
3950
> For ordered maps, the `getByIndex` method returns a list containing exactly 2 entries.
4051
> The first entry is the member name, the second entry is the member value.
@@ -76,8 +87,8 @@ $permissions->indexByName('geolocation'): // returns 1
7687
> The `getByName` method will throw an `InvalidOffset` exception if no member exists for the given `$offset`.
7788
7889
> [!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`.
8192
8293
### Accessing the parameters values
8394

@@ -92,9 +103,9 @@ parameter.
92103
> The `parameterByName` proxy the result from `valueByName`.
93104
> The `parameterByIndex` proxy the result from `valueByIndex`.
94105
95-
## Building and Updating Structured Fields Values
106+
## Building and Updating COntainers
96107

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
98109
using immutable value objects any change to the value object will return a new instance
99110
with the changes applied and leave the original instance unchanged.
100111

@@ -116,7 +127,7 @@ echo $value->toHttpValue(); //"b=?0, a=bar, c=@1671800423"
116127
echo $value; //"b=?0, a=bar, c=@1671800423"
117128
```
118129

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:
120131

121132
```php
122133
use Bakame\Http\StructuredFields\Parameters;
@@ -225,8 +236,8 @@ echo $field->removeByNames('expire', 'httponly', 'max-age')->toHttpValue(); // r
225236

226237
### Automatic conversion
227238

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.
230241

231242
If the submitted type is:
232243

@@ -384,21 +395,20 @@ Both objects provide additional modifying methods to help deal with parameters.
384395
You can attach and update the associated `Parameters` instance using the following methods.
385396

386397
```php
398+
$field->withParameters(Parameters $parameters): static;
387399
$field->addParameter(string $name, mixed $value): static;
388400
$field->appendParameter(string $name, mixed $value): static;
389401
$field->prependParameter(string $name, mixed $value): static;
390-
$field->withoutParametersByNames(string ...$names): static;
391-
$field->withoutAnyParameter(): static;
392-
$field->withParameters(Parameters $parameters): static;
393402
$field->pushParameters(array ...$pairs): static
394403
$field->unshiftParameters(array ...$pairs): static
395404
$field->insertParameters(int $index, array ...$pairs): static
396405
$field->replaceParameter(int $index, array $pair): static
397406
$field->withoutParametersByNames(string ...$names): static
398407
$field->withoutParametersByIndices(int ...$indices): static
408+
$field->withoutAnyParameter(): static;
399409
```
400410

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:
402412

403413
- the first array member is the parameter `$name`
404414
- the second array member is the parameter `$value`

0 commit comments

Comments
 (0)