@@ -17,8 +17,8 @@ use Bakame\Http\StructuredFields\DataType;
17
17
use Bakame\Http\StructuredFields\Token;
18
18
19
19
//1 - parsing an Accept Header
20
- $headerValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';
21
- $field = DataType::List->parse($headerValue );
20
+ $fieldValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';
21
+ $field = DataType::List->parse($fieldValue );
22
22
$field[2]->value()->toString(); // returns 'application/xml'
23
23
$field[2]->parameter('q'); // returns (float) 0.9
24
24
$field[0]->value()->toString(); // returns 'text/html'
@@ -69,11 +69,11 @@ header. Content validation is out of scope for this library.
69
69
> [ !NOTE]
70
70
> New in version 1.2.0
71
71
72
- The ` DataType ` enum serves as a factory class to quickly parse and build a structured field.
73
- The enum list all available data type according to the RFC . To parse a header you need to
74
- give the ` parse ` method a string or a stringable object. On success, it will return a
75
- ` Bakame\Http\StruncturedFields\StruncturedField ` implementing object otherwise an
76
- exception will be thrown.
72
+ The ` DataType ` enum list all available data type according to the RFC. It is also a
73
+ Factory to enable parsing and building such data types . To parse a header you need
74
+ to give the ` parse ` method a string or a stringable object. On success, it will
75
+ return a ` Bakame\Http\StruncturedFields\StruncturedField ` implementing object
76
+ otherwise an exception will be thrown.
77
77
78
78
``` php
79
79
$headerLine = 'bar;baz=42'; //the raw header line is a structured field item
@@ -103,14 +103,12 @@ echo DataType::List->build([
103
103
// display "dumela lefatshe";a=?0, ("a" "b" @1703319068);a
104
104
```
105
105
106
- The data type can be given as a string or using the ` DataType ` enum.
107
-
108
106
#### Using specific named constructor
109
107
110
- The package provides specific classes for each data type. if you do not wish to
111
- use the ` DataType ` factoring, parsing the header value is done via the
112
- ` fromHttpValue ` named constructor. The method is attached to each library's
113
- structured fields representation as shown below:
108
+ To complement the factory and to allow for more fine-grained manipulations, the package
109
+ provides specific classes for each data type. if you do not wish to use the ` DataType `
110
+ factoring, parsing the header value is done via the ` fromHttpValue ` named constructor.
111
+ The method is attached to each library's structured fields representation as shown below:
114
112
115
113
``` php
116
114
declare(strict_types=1);
@@ -230,18 +228,18 @@ The table below summarizes the item value type.
230
228
| Date | class ` DateTimeImmutable ` | ` Type::Date ` |
231
229
| DisplayString | class ` DisplayString ` | ` Type::DisplayString ` |
232
230
233
- The Enum ` Type ` which list all available types can be use to determine the RFC type
234
- corresponding to a PHP structure using the ` Type::fromValue ` static method.
231
+ The Enum ` Type ` which list all available types can be used to determine the RFC type
232
+ corresponding to a PHP structure using the ` Type::fromVariable ` static method.
235
233
The method will throw if the structure is not recognized Alternatively it is possible
236
234
to use the ` Type::tryFromValue ` which will instead return ` null ` on unindentified type.
237
235
On success both methods returns the corresponding enum ` Type ` .
238
236
239
237
``` php
240
238
use Bakame\Http\StructuredFields\Type;
241
239
242
- echo Type::fromValue (42); // returns Type::Integer
243
- echo Type::fromValue (42.0)->name; // returns 'Decimal'
244
- echo Type::fromValue (new SplTempFileObject()); // throws InvalidArgument
240
+ echo Type::fromVariable (42)->value ; // returns 'integer'
241
+ echo Type::fromVariable (42.0)->name; // returns 'Decimal'
242
+ echo Type::fromVariable (new SplTempFileObject()); // throws InvalidArgument
245
243
echo Type::tryFromValue(new SplTempFileObject()); // returns null
246
244
```
247
245
0 commit comments