Skip to content

Commit fb0ed44

Browse files
committed
Update README text
1 parent 9376c63 commit fb0ed44

File tree

1 file changed

+29
-35
lines changed

1 file changed

+29
-35
lines changed

README.md

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ The package can be used to:
2121
- infer fields and data types from HTTP Structured Fields;
2222

2323
```php
24-
use Bakame\Http\StructuredFields\Item;
24+
use Bakame\Http\StructuredFields;
2525

26-
$field = Item::from("/terms", ['rel' => "copyright", 'anchor' => '#foo']);
26+
$field = StructuredFields\Item::from("/terms", ['rel' => "copyright", 'anchor' => '#foo']);
2727
echo $field->toHttpValue(); //display "/terms";rel="copyright";anchor="#foo"
2828
echo $field->value; //display "/terms"
2929
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
6161
- Serializing is done via a common `toHttpValue` public method. The method returns the normalized string representation suited for HTTP textual representation.
6262

6363
```php
64-
use Bakame\Http\StructuredFields\Dictionary;
65-
use Bakame\Http\StructuredFields\Item;
66-
use Bakame\Http\StructuredFields\OrderedList;
64+
use Bakame\Http\StructuredFields;
6765

68-
$dictionary = Dictionary::fromHttpValue("a=?0, b, c=?1; foo=bar");
66+
$dictionary = StructuredFields\Dictionary::fromHttpValue("a=?0, b, c=?1; foo=bar");
6967
echo $dictionary->toHttpValue(); // "a=?0, b, c;foo=bar"
7068

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');
7270
echo $list->toHttpValue(); // "("foo";a=1;b=2);lvl=5, ("bar" "baz");lvl=1"
7371

74-
$item = Item::fromHttpValue('"foo";a=1;b=2"');
72+
$item = StructuredFields\Item::fromHttpValue('"foo";a=1;b=2"');
7573
echo $item->toHttpValue(); // "foo";a=1;b=2
7674
```
7775

@@ -116,9 +114,9 @@ Instantiation via type recognition is done using the `Item::from` named construc
116114
- 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;
117115

118116
```php
119-
use Bakame\Http\StructuredFields\Item;
117+
use Bakame\Http\StructuredFields;
120118

121-
$item = Item::from("hello world", ["a" => 1]);
119+
$item = StructuredFields\Item::from("hello world", ["a" => 1]);
122120
$item->value; //returns "hello world"
123121
$item->isString(); //return true
124122
$item->isToken(); //return false
@@ -134,13 +132,13 @@ Once instantiated, accessing `Item` properties is done via two (2) readonly prop
134132
**Of note: to instantiate a decimal number type a float MUST be used as the first argument of `Item::from`.**
135133

136134
```php
137-
use Bakame\Http\StructuredFields\Item;
135+
use Bakame\Http\StructuredFields;
138136

139-
$decimal = Item::from(42.0);
137+
$decimal = StructuredFields\Item::from(42.0);
140138
$decimal->isDecimal(); //return true
141139
$decimal->isInteger(); //return false
142140

143-
$item = Item::from(42);
141+
$item = StructuredFields\Item::from(42);
144142
$item->isDecimal(); //return false
145143
$item->isInteger(); //return true
146144
```
@@ -163,9 +161,9 @@ At any given time it is possible with each of these objects to:
163161
- clear the container using the `clear` method;
164162

165163
```php
166-
use Bakame\Http\StructuredFields\Parameters;
164+
use Bakame\Http\StructuredFields;
167165

168-
$parameters = Parameters::fromAssociative(['a' => 1, 'b' => 2, 'c' => "hello world"]);
166+
$parameters = StructuredFields\Parameters::fromAssociative(['a' => 1, 'b' => 2, 'c' => "hello world"]);
169167
count($parameters); // return 2
170168
$parameters->isEmpty(); // returns false
171169
$parameters->toHttpValue(); // return ";a=1;b=2"
@@ -192,12 +190,10 @@ key to its members as such they expose the following methods:
192190
- `mergePairs` merge multiple instances of iterable structure as pairs constructs;
193191

194192
```php
195-
use Bakame\Http\StructuredFields\Dictionary;
196-
use Bakame\Http\StructuredFields\Item;
197-
use Bakame\Http\StructuredFields\Token;
193+
use Bakame\Http\StructuredFields;
198194

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')]));
201197
$dictionary->prepend('a', false);
202198
$dictionary->toHttpValue(); //returns "a=?0, b, c;foo=bar"
203199
$dictionary->has('a'); //return true
@@ -223,19 +219,17 @@ The `Parameters` instance exposes the following methods:
223219
- `Parameters::merge` also accepts iterable as associative key-value as part of the variadic signature.
224220

225221
```php
226-
use Bakame\Http\StructuredFields\Parameters;
227-
use Bakame\Http\StructuredFields\Item;
228-
use Bakame\Http\StructuredFields\Token;
222+
use Bakame\Http\StructuredFields;
229223

230-
$parameters = Parameters::fromAssociative(['b' => true, 'foo' => 'bar']);
224+
$parameters = StructuredFields\Parameters::fromAssociative(['b' => true, 'foo' => 'bar']);
231225
$parameters->keys(); // returns ['b', 'foo']
232226
$parameters->values(); // returns [true, 'bar']
233227
$parameters->value('b'); // returns true
234228
$parameters->get('b'); // returns Item::from(true)
235229
iterator_to_array($parameters->toPairs(), true); // returns [['b', Item::from(true)], ['foo', Item::from('bar')]]
236230
iterator_to_array($parameters, true); // returns ['b' => Item::from(true), 'foo' => Item::from('bar')]
237231
$parameters->mergeAssociative(
238-
Parameters::fromAssociative(['b' => true, 'foo' => 'foo']),
232+
StructuredFields\Parameters::fromAssociative(['b' => true, 'foo' => 'foo']),
239233
['b' => 'false']
240234
);
241235
$parameters->toHttpValue(); // returns ;b="false";foo="foo"
@@ -264,18 +258,19 @@ to enable manipulation their content.
264258
**EVERY CHANGE IN THE LIST WILL RE-INDEX THE LIST AS TO NOT EXPOSE MISSING INDEXES**
265259

266260
```php
267-
use Bakame\Http\StructuredFields\InnerList;
268-
use Bakame\Http\StructuredFields\OrderedList;
269-
use Bakame\Http\StructuredFields\Token;
261+
use Bakame\Http\StructuredFields;
270262

271-
$innerList = InnerList::fromList([42, 42.0, "42"], ["a" => true]);
263+
$innerList = StructuredFields\InnerList::fromList([42, 42.0, "42"], ["a" => true]);
272264
$innerList->has(2); //return true
273265
$innerList->has(42); //return false
274-
$innerList->push(Token::fromString('forty-two'));
266+
$innerList->push(StructuredFields\Token::fromString('forty-two'));
275267
$innerList->remove(0, 2);
276268
echo $innerList->toHttpValue(); //returns '(42.0 forty-two);a'
277269

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+
);
279274
echo $orderedList->toHttpValue(); //returns '"42";foo="bar", (42.0 forty-two);a'
280275
```
281276

@@ -287,11 +282,10 @@ RFC but the main ones are:
287282
- `InnerList` has a `Parameters` instance attached to it that you can access via its readonly property `parameters`, not `OrderedList`;
288283

289284
```php
290-
use Bakame\Http\StructuredFields\InnerList;
291-
use Bakame\Http\StructuredFields\Parameters;
285+
use Bakame\Http\StructuredFields;
292286

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
295289
$innerList->parameters->value('a'); // returns true
296290
```
297291

0 commit comments

Comments
 (0)