@@ -21,9 +21,9 @@ The package can be used to:
21
21
- infer fields and data types from HTTP Structured Fields;
22
22
23
23
``` php
24
- use Bakame\Http\StructuredFields\Item ;
24
+ use Bakame\Http\StructuredFields;
25
25
26
- $field = Item::from("/terms", ['rel' => "copyright", 'anchor' => '#foo']);
26
+ $field = StructuredFields\ Item::from("/terms", ['rel' => "copyright", 'anchor' => '#foo']);
27
27
echo $field->toHttpValue(); //display "/terms";rel="copyright";anchor="#foo"
28
28
echo $field->value; //display "/terms"
29
29
echo $field->parameters->value('rel'); //display "copyright"
@@ -61,17 +61,15 @@ representation of the field and to serialize the value object back to the textua
61
61
- Serializing is done via a common ` toHttpValue ` public method. The method returns the normalized string representation suited for HTTP textual representation.
62
62
63
63
``` php
64
- use Bakame\Http\StructuredFields\Dictionary;
65
- use Bakame\Http\StructuredFields\Item;
66
- use Bakame\Http\StructuredFields\OrderedList;
64
+ use Bakame\Http\StructuredFields;
67
65
68
- $dictionary = Dictionary::fromHttpValue("a=?0, b, c=?1; foo=bar");
66
+ $dictionary = StructuredFields\ Dictionary::fromHttpValue("a=?0, b, c=?1; foo=bar");
69
67
echo $dictionary->toHttpValue(); // "a=?0, b, c;foo=bar"
70
68
71
- $list = OrderedList::fromHttpValue('("foo"; a=1;b=2);lvl=5, ("bar" "baz");lvl=1');
69
+ $list = StructuredFields\ OrderedList::fromHttpValue('("foo"; a=1;b=2);lvl=5, ("bar" "baz");lvl=1');
72
70
echo $list->toHttpValue(); // "("foo";a=1;b=2);lvl=5, ("bar" "baz");lvl=1"
73
71
74
- $item = Item::fromHttpValue('"foo";a=1;b=2"');
72
+ $item = StructuredFields\ Item::fromHttpValue('"foo";a=1;b=2"');
75
73
echo $item->toHttpValue(); // "foo";a=1;b=2
76
74
```
77
75
@@ -116,9 +114,9 @@ Instantiation via type recognition is done using the `Item::from` named construc
116
114
- The second argument, which is optional, MUST be an iterable construct where its index represents the parameter key and its value an item or a item type value;
117
115
118
116
``` php
119
- use Bakame\Http\StructuredFields\Item ;
117
+ use Bakame\Http\StructuredFields;
120
118
121
- $item = Item::from("hello world", ["a" => 1]);
119
+ $item = StructuredFields\ Item::from("hello world", ["a" => 1]);
122
120
$item->value; //returns "hello world"
123
121
$item->isString(); //return true
124
122
$item->isToken(); //return false
@@ -134,13 +132,13 @@ Once instantiated, accessing `Item` properties is done via two (2) readonly prop
134
132
** Of note: to instantiate a decimal number type a float MUST be used as the first argument of ` Item::from ` .**
135
133
136
134
``` php
137
- use Bakame\Http\StructuredFields\Item ;
135
+ use Bakame\Http\StructuredFields;
138
136
139
- $decimal = Item::from(42.0);
137
+ $decimal = StructuredFields\ Item::from(42.0);
140
138
$decimal->isDecimal(); //return true
141
139
$decimal->isInteger(); //return false
142
140
143
- $item = Item::from(42);
141
+ $item = StructuredFields\ Item::from(42);
144
142
$item->isDecimal(); //return false
145
143
$item->isInteger(); //return true
146
144
```
@@ -163,9 +161,9 @@ At any given time it is possible with each of these objects to:
163
161
- clear the container using the ` clear ` method;
164
162
165
163
``` php
166
- use Bakame\Http\StructuredFields\Parameters ;
164
+ use Bakame\Http\StructuredFields;
167
165
168
- $parameters = Parameters::fromAssociative(['a' => 1, 'b' => 2, 'c' => "hello world"]);
166
+ $parameters = StructuredFields\ Parameters::fromAssociative(['a' => 1, 'b' => 2, 'c' => "hello world"]);
169
167
count($parameters); // return 2
170
168
$parameters->isEmpty(); // returns false
171
169
$parameters->toHttpValue(); // return ";a=1;b=2"
@@ -192,12 +190,10 @@ key to its members as such they expose the following methods:
192
190
- ` mergePairs ` merge multiple instances of iterable structure as pairs constructs;
193
191
194
192
``` php
195
- use Bakame\Http\StructuredFields\Dictionary;
196
- use Bakame\Http\StructuredFields\Item;
197
- use Bakame\Http\StructuredFields\Token;
193
+ use Bakame\Http\StructuredFields;
198
194
199
- $dictionary = Dictionary::fromPairs([['b', true]]);
200
- $dictionary->append('c', Item::from(true, ['foo' => Token::fromString('bar')]));
195
+ $dictionary = StructuredFields\ Dictionary::fromPairs([['b', true]]);
196
+ $dictionary->append('c', StructuredFields\ Item::from(true, ['foo' => StructuredFields\ Token::fromString('bar')]));
201
197
$dictionary->prepend('a', false);
202
198
$dictionary->toHttpValue(); //returns "a=?0, b, c;foo=bar"
203
199
$dictionary->has('a'); //return true
@@ -223,19 +219,17 @@ The `Parameters` instance exposes the following methods:
223
219
- ` Parameters::merge ` also accepts iterable as associative key-value as part of the variadic signature.
224
220
225
221
``` php
226
- use Bakame\Http\StructuredFields\Parameters;
227
- use Bakame\Http\StructuredFields\Item;
228
- use Bakame\Http\StructuredFields\Token;
222
+ use Bakame\Http\StructuredFields;
229
223
230
- $parameters = Parameters::fromAssociative(['b' => true, 'foo' => 'bar']);
224
+ $parameters = StructuredFields\ Parameters::fromAssociative(['b' => true, 'foo' => 'bar']);
231
225
$parameters->keys(); // returns ['b', 'foo']
232
226
$parameters->values(); // returns [true, 'bar']
233
227
$parameters->value('b'); // returns true
234
228
$parameters->get('b'); // returns Item::from(true)
235
229
iterator_to_array($parameters->toPairs(), true); // returns [['b', Item::from(true)], ['foo', Item::from('bar')]]
236
230
iterator_to_array($parameters, true); // returns ['b' => Item::from(true), 'foo' => Item::from('bar')]
237
231
$parameters->mergeAssociative(
238
- Parameters::fromAssociative(['b' => true, 'foo' => 'foo']),
232
+ StructuredFields\ Parameters::fromAssociative(['b' => true, 'foo' => 'foo']),
239
233
['b' => 'false']
240
234
);
241
235
$parameters->toHttpValue(); // returns ;b="false";foo="foo"
@@ -264,18 +258,19 @@ to enable manipulation their content.
264
258
** EVERY CHANGE IN THE LIST WILL RE-INDEX THE LIST AS TO NOT EXPOSE MISSING INDEXES**
265
259
266
260
``` php
267
- use Bakame\Http\StructuredFields\InnerList;
268
- use Bakame\Http\StructuredFields\OrderedList;
269
- use Bakame\Http\StructuredFields\Token;
261
+ use Bakame\Http\StructuredFields;
270
262
271
- $innerList = InnerList::fromList([42, 42.0, "42"], ["a" => true]);
263
+ $innerList = StructuredFields\ InnerList::fromList([42, 42.0, "42"], ["a" => true]);
272
264
$innerList->has(2); //return true
273
265
$innerList->has(42); //return false
274
- $innerList->push(Token::fromString('forty-two'));
266
+ $innerList->push(StructuredFields\ Token::fromString('forty-two'));
275
267
$innerList->remove(0, 2);
276
268
echo $innerList->toHttpValue(); //returns '(42.0 forty-two);a'
277
269
278
- $orderedList = OrderedList::from(Item::from("42", ["foo" => "bar"]), $innerList);
270
+ $orderedList = StructuredFields\OrderedList::from(
271
+ StructuredFields\Item::from("42", ["foo" => "bar"]),
272
+ $innerList
273
+ );
279
274
echo $orderedList->toHttpValue(); //returns '"42";foo="bar", (42.0 forty-two);a'
280
275
```
281
276
@@ -287,11 +282,10 @@ RFC but the main ones are:
287
282
- ` InnerList ` has a ` Parameters ` instance attached to it that you can access via its readonly property ` parameters ` , not ` OrderedList ` ;
288
283
289
284
``` php
290
- use Bakame\Http\StructuredFields\InnerList;
291
- use Bakame\Http\StructuredFields\Parameters;
285
+ use Bakame\Http\StructuredFields;
292
286
293
- $innerList = InnerList::fromList([42, 42.0, "42"], ["a" => true]);
294
- $innerList->parameters; //returns a Parameters object
287
+ $innerList = StructuredFields\ InnerList::fromList([42, 42.0, "42"], ["a" => true]);
288
+ $innerList->parameters; //returns a StructuredFields\ Parameters object
295
289
$innerList->parameters->value('a'); // returns true
296
290
```
297
291
0 commit comments