@@ -141,23 +141,16 @@ is possible to:
141
141
- iterate over each contained element and its optional associated key via the ` IteratorAggregate ` interface;
142
142
- tell whether the container is empty via an ` isEmpty ` method;
143
143
- know the number of elements contained in the container via the ` Countable ` interface;
144
- - tell whether an element is attached to the container using its ` index ` or ` key ` via ` hasIndex ` and ` hasKey ` methods;
145
- - get any element by its string ` key ` or by its integer ` index ` via ` getByKey ` and ` getByIndex ` methods when applicable;
146
144
- merge multiple instance of the same container using the ` merge ` method;
147
145
148
146
``` php
149
147
use Bakame\Http\StructuredFields\Parameters;
150
148
151
149
$parameters = new Parameters(['a' => 1, 'b' => 2, 'c' => Item::from("hello world")]);
152
150
count($parameters); // return 2
153
- $parameters->getByKey('b'); // return Item::from(2);
154
- $parameters->getByIndex(-1); // return Item::from("hello world");
155
- $parameters->hasKey(42); // return false because the key does not exist.
151
+ $parameters->isEmpty(); // returns false
156
152
$parameters->toHttpValue(); // return ";a=1;b=2"
157
- $parameters->keys(); // return ["a", "b", "c"]
158
153
```
159
- - * ` getByIndex ` supports negative index*
160
- - * Item types are inferred using ` Item::from ` if a ` Item ` object is not submitted.*
161
154
162
155
#### Ordered Maps
163
156
@@ -168,6 +161,8 @@ key to its members as such they expose the following methods:
168
161
- ` append ` always add an element at the end of the container, if already present the previous value is removed;
169
162
- ` prepend ` always add an element at the beginning of the container, if already present the previous value is removed;
170
163
- ` delete ` to remove elements based on their associated keys;
164
+ - tell whether an element is attached to the container using its ` index ` or ` key ` via ` hasIndex ` and ` hasKey ` methods;
165
+ - get any element by its string ` key ` or by its integer ` index ` via ` getByKey ` and ` getByIndex ` methods when applicable;
171
166
172
167
``` php
173
168
use Bakame\Http\StructuredFields\Dictionary;
@@ -181,11 +176,15 @@ $dictionary->toHttpValue(); //returns "a=?0, b, c;foo=bar"
181
176
$dictionary->hasKey('a'); //return true
182
177
$dictionary->hasKey('foo'); //return false
183
178
$dictionary->getByIndex(1); //return Item::fromBoolean(true)
179
+ $dictionary->hasIndex(-1); //return Item::fromBoolean(true)
184
180
$dictionary->append('z', 42.0);
185
181
$dictionary->delete('b', 'c');
186
182
echo $dictionary->toHttpValue(); //returns "a=?0, z=42.0"
187
183
```
188
184
185
+ ** Item types are inferred using ` Item::from ` if a ` Item ` object is not submitted.**
186
+
187
+ - ` getByIndex ` supports negative index
189
188
- ` Parameters ` can only contains ` Item ` instances
190
189
- ` Dictionary ` instance can contain ` Item ` and ` InnerList ` instances.
191
190
@@ -194,6 +193,8 @@ echo $dictionary->toHttpValue(); //returns "a=?0, z=42.0"
194
193
The ` OrderedList ` and the ` InnerList ` classes are list of members
195
194
that act as containers and also expose the following methods
196
195
196
+ - ` get ` to access an element at a given index (negative indexes are supported)
197
+ - ` has ` tell whether an element is attached to the container using its ` index ` ;
197
198
- ` push ` to add elements at the end of the list;
198
199
- ` unshift ` to add elements at the beginning of the list;
199
200
- ` insert ` to add elements at a given position in the list;
@@ -202,14 +203,16 @@ that act as containers and also expose the following methods
202
203
203
204
to enable manipulation their content.
204
205
206
+ ** Item types are inferred using ` Item::from ` if a ` Item ` object is not submitted.**
207
+
205
208
** EVERY CHANGE IN THE LIST WILL RE-INDEX THE LIST AS TO NOT EXPOSE MISSING INDEXES**
206
209
207
210
``` php
208
211
use Bakame\Http\StructuredFields\OrderedList;
209
212
210
- $list = OrderedList::fromHttpValue("(\ "foo\" \ "bar\ "), (\ "baz\ "), (\ "bat\" \ "one\ "), ()" );
211
- $list->hasIndex (2); //return true
212
- $list->hasIndex (42); //return false
213
+ $list = OrderedList::fromHttpValue('( "foo" "bar"), ("baz"), ("bat" "one"), ()' );
214
+ $list->has (2); //return true
215
+ $list->has (42); //return false
213
216
$list->push(42);
214
217
$list->remove(0, 2);
215
218
echo $list->toHttpValue(); //returns "("baz"), (), 42.0"
0 commit comments