Skip to content

Commit ccedea1

Browse files
committed
Improve documentation
1 parent e18f6af commit ccedea1

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

README.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ The RFC defines different data types to handle structured fields values.
7676

7777
### Items
7878

79-
The Item may be considered the minimal building block for structired fields the following explains how to build
79+
The Item is the minimal building block for structured fields the following explains how to build
8080
and interact with them.
8181

82-
#### Types
82+
#### Bare Items
8383

84-
Item have different types [defined in the RFC](https://www.rfc-editor.org/rfc/rfc8941.html#section-3.3). They are
85-
translated to PHP native type when possible. Two additional classes
84+
Item have different types [defined in the RFC](https://www.rfc-editor.org/rfc/rfc8941.html#section-3.3).
85+
They are translated to PHP native type when possible. Two additional classes
8686

8787
- `Bakame\Http\StructuredFields\Token` and
8888
- `Bakame\Http\StructuredFields\ByteSequence`
@@ -98,12 +98,10 @@ are used to represent non-native types as shown in the table below:
9898
| Token | class `Token` | `Item::isToken` |
9999
| Byte Sequence | class `ByteSequence` | `Item::isByteSequence` |
100100

101-
#### Parameters
101+
#### Complex Items
102102

103-
As explain in the RFC, `Parameters` are an ordered map of key-value pairs that can be
104-
associated with an `Item`. They can be associated **BUT** the items they contain
105-
can not themselves contain `Parameters` instance. More on parameters
106-
public API will be cover in subsequent paragraphs.
103+
As explain in the RFC, Item can be associated with `Parameters` that are ordered maps of key-value pairs, where the
104+
keys are string and the value are bare items. Their public API will be cover in subsequent paragraphs.
107105

108106
#### Usage
109107

@@ -116,15 +114,19 @@ $item = Item::from("hello world", ["a" => 1]);
116114
$item->value(); //returns "hello world"
117115
$item->isString(); //return true
118116
$item->isToken(); //return false
119-
$item->parameters()->get("a")->value(); //returns 1
117+
$item->parameter("a")->value(); //returns 1
120118
```
121119

122-
Once instantiated, accessing `Item` properties is done via two methods:
120+
- The first argument represents one of the six (6) item type value;
121+
- The second argument MUST be an iterable construct where its index represents the parameter key and its value an item or a item type value;
122+
123+
Once instantiated, accessing `Item` properties is done via three (3) methods:
123124

124125
- `Item::value()` which returns the instance underlying value
125126
- `Item::parameters()` which returns the parameters associated to the `Item` as a distinct `Parameters` object
127+
- `Item::parameter(string $key)` which returns the HTTP data type attached to the parameter `$key`.
126128

127-
**To instantiate a decimal number a float MUST be used as the first argument input.**
129+
**Of note: to instantiate a decimal number type a float MUST be used as the first argument input.**
128130

129131
```php
130132
use Bakame\Http\StructuredFields\Item;
@@ -140,7 +142,7 @@ $item->isInteger(); //return true
140142

141143
### Containers
142144

143-
Apart from the `Item`, the RFC defines different containers with different requirements. The
145+
Apart from the `Item`, the RFC defines different items containers with different requirements. The
144146
package exposes those containers via the following value objects:
145147

146148
- `Dictionary`,
@@ -244,10 +246,19 @@ echo $orderedList->toHttpValue(); //returns '"42";foo="bar", (42.0 forty-two);a'
244246
The distinction between `InnerList` and `OrderedList` is well explained in the
245247
RFC but the main ones are:
246248

247-
- `InnerList` members can be `Items` or `null`;
248-
- `OrderedList` members can be `InnerList`, `Items`;
249+
- `InnerList` members must be `Items`;
250+
- `OrderedList` members must be `InnerList` or `Items`;
249251
- `InnerList` can have a `Parameters` instance attached to it, not `OrderedList`;
250252

253+
```php
254+
use Bakame\Http\StructuredFields\InnerList;
255+
use Bakame\Http\StructuredFields\Parameters;
256+
257+
$innerList = InnerList::fromMembers([42, 42.0, "42"], ["a" => true]);
258+
$innerList->parameter('a'); //returns true
259+
$innerList->parameters(); //returns a Parameters object
260+
```
261+
251262
Contributing
252263
-------
253264

0 commit comments

Comments
 (0)