@@ -76,13 +76,13 @@ The RFC defines different data types to handle structured fields values.
76
76
77
77
### Items
78
78
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
80
80
and interact with them.
81
81
82
- #### Types
82
+ #### Bare Items
83
83
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
86
86
87
87
- ` Bakame\Http\StructuredFields\Token ` and
88
88
- ` Bakame\Http\StructuredFields\ByteSequence `
@@ -98,12 +98,10 @@ are used to represent non-native types as shown in the table below:
98
98
| Token | class ` Token ` | ` Item::isToken ` |
99
99
| Byte Sequence | class ` ByteSequence ` | ` Item::isByteSequence ` |
100
100
101
- #### Parameters
101
+ #### Complex Items
102
102
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.
107
105
108
106
#### Usage
109
107
@@ -116,15 +114,19 @@ $item = Item::from("hello world", ["a" => 1]);
116
114
$item->value(); //returns "hello world"
117
115
$item->isString(); //return true
118
116
$item->isToken(); //return false
119
- $item->parameters()->get ("a")->value(); //returns 1
117
+ $item->parameter ("a")->value(); //returns 1
120
118
```
121
119
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:
123
124
124
125
- ` Item::value() ` which returns the instance underlying value
125
126
- ` 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 ` .
126
128
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.**
128
130
129
131
``` php
130
132
use Bakame\Http\StructuredFields\Item;
@@ -140,7 +142,7 @@ $item->isInteger(); //return true
140
142
141
143
### Containers
142
144
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
144
146
package exposes those containers via the following value objects:
145
147
146
148
- ` Dictionary ` ,
@@ -244,10 +246,19 @@ echo $orderedList->toHttpValue(); //returns '"42";foo="bar", (42.0 forty-two);a'
244
246
The distinction between ` InnerList ` and ` OrderedList ` is well explained in the
245
247
RFC but the main ones are:
246
248
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 ` ;
249
251
- ` InnerList ` can have a ` Parameters ` instance attached to it, not ` OrderedList ` ;
250
252
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
+
251
262
Contributing
252
263
-------
253
264
0 commit comments