@@ -34,7 +34,7 @@ echo OuterList::new(
34
34
'max-age' => 2500,
35
35
'secure' => true,
36
36
'httponly' => true,
37
- 'samesite' => BakameToken ::fromString('lax'),
37
+ 'samesite' => Token ::fromString('lax'),
38
38
])
39
39
)
40
40
->toHttpValue();
@@ -134,7 +134,34 @@ The table below summarizes the item value type.
134
134
| Byte Sequence | class ` ByteSequence ` | ` Type::ByteSequence ` |
135
135
| Date | class ` DateTimeImmutable ` | ` Type::Date ` |
136
136
137
- The RFC define two (2) specific data types that can not be represented by
137
+ The Enum ` Type ` which list all available types can be use to determine the RFC type
138
+ corresponding to a PHP structure using the ` Type::fromValue ` static method.
139
+ The method will throw if the structure is not recognized Alternatively it is possible
140
+ to use the ` Type::tryFromValue ` which will instead return ` null ` on unindentified type.
141
+ On success both methods returns the corresponding enum ` Type ` .
142
+
143
+ ``` php
144
+ use Bakame\Http\StructuredFields\Type;
145
+
146
+ echo Type::fromValue(42); // returns Type::Integer
147
+ echo Type::fromValue(42.0)->name; // returns 'Decimal'
148
+ echo Type::fromValue(new SplTempFileObject()); // throws TypeError
149
+ echo Type::tryFromValue(new SplTempFileObject()); // returns null
150
+ ```
151
+
152
+ To ease validation a ` Type::equals ` method is exposed to check if the ` Item ` has
153
+ the expected type. It can also be used to compare types.
154
+
155
+ ``` php
156
+ use Bakame\Http\StructuredFields\Type;
157
+
158
+ $field = Item::fromHttpValue('"foo"');
159
+ Type::Date->equals($field); // returns false
160
+ Type::String->equals($field); // returns true;
161
+ Type::Boolean->equals(Type::String); // returns false
162
+ ```
163
+
164
+ The RFC defines two (2) specific data types that can not be represented by
138
165
PHP default type system, for them, we have defined two classes ` Token `
139
166
and ` ByteSequence ` to help with their representation.
140
167
@@ -183,8 +210,6 @@ use Bakame\Http\StructuredFields\Type;
183
210
$item = Item::fromHttpValue('@1234567890');
184
211
$item->type(); // return Type::Date;
185
212
$item->value() // return the equivalent to DateTimeImmutable('@1234567890');
186
- // you can also do
187
- Type::Date->equals($item); // returns true
188
213
```
189
214
190
215
#### Containers
0 commit comments