@@ -176,15 +176,16 @@ Per the RFC, items can have different types that are translated to PHP using:
176
176
177
177
The table below summarizes the item value type.
178
178
179
- | RFC Type | PHP Type | Package Enum Type |
180
- | ---------------| ---------------------------| ----------------------|
181
- | Integer | ` int ` | ` Type::Integer ` |
182
- | Decimal | ` float ` | ` Type::Decimal ` |
183
- | String | ` string ` | ` Type::String ` |
184
- | Boolean | ` bool ` | ` Type::Boolean ` |
185
- | Token | class ` Token ` | ` Type::Token ` |
186
- | Byte Sequence | class ` ByteSequence ` | ` Type::ByteSequence ` |
187
- | Date | class ` DateTimeImmutable ` | ` Type::Date ` |
179
+ | RFC Type | PHP Type | Package Enum Type |
180
+ | ---------------| ---------------------------| -----------------------|
181
+ | Integer | ` int ` | ` Type::Integer ` |
182
+ | Decimal | ` float ` | ` Type::Decimal ` |
183
+ | String | ` string ` | ` Type::String ` |
184
+ | Boolean | ` bool ` | ` Type::Boolean ` |
185
+ | Token | class ` Token ` | ` Type::Token ` |
186
+ | Byte Sequence | class ` ByteSequence ` | ` Type::ByteSequence ` |
187
+ | Date | class ` DateTimeImmutable ` | ` Type::Date ` |
188
+ | DisplayString | class ` DisplayString ` | ` Type::DisplayString ` |
188
189
189
190
The Enum ` Type ` which list all available types can be use to determine the RFC type
190
191
corresponding to a PHP structure using the ` Type::fromValue ` static method.
@@ -213,9 +214,9 @@ Type::String->equals($field); // returns true;
213
214
Type::Boolean->equals(Type::String); // returns false
214
215
```
215
216
216
- The RFC defines two (2 ) specific data types that can not be represented by
217
- PHP default type system, for them, we have defined two classes ` Token `
218
- and ` ByteSequence ` to help with their representation.
217
+ The RFC defines three (3 ) specific data types that can not be represented by
218
+ PHP default type system, for them, we have defined three classes ` Token ` ,
219
+ ` ByteSequence ` and ` DisplayString ` to help with their representation.
219
220
220
221
``` php
221
222
use Bakame\Http\StructuredFields\Token;
@@ -224,31 +225,40 @@ use Bakame\Http\StructuredFields\ByteSequence;
224
225
Token::fromString(string|Stringable $value): Token
225
226
ByteSequence::fromDecoded(string|Stringable $value): ByteSequence;
226
227
ByteSequence::fromEncoded(string|Stringable $value): ByteSequence;
228
+ DisplayString::fromDecoded(string|Stringable $value): DisplayString;
229
+ DisplayString::fromEncoded(string|Stringable $value): DisplayString;
227
230
```
228
231
229
- Both classes are final and immutable; their value can not be modified once
232
+ All classes are final and immutable; their value can not be modified once
230
233
instantiated. To access their value, they expose the following API:
231
234
232
235
``` php
233
236
use Bakame\Http\StructuredFields\Token;
234
237
use Bakame\Http\StructuredFields\ByteSequence;
238
+ use Bakame\Http\StructuredFields\DisplayString;
235
239
236
240
$token = Token::fromString('application/text+xml');
237
241
echo $token->toString(); // returns 'application/text+xml'
238
242
239
- $byte = ByteSequence::fromDecoded('Hello world!');
243
+ $byte = DisplayString::fromDecoded('füü');
244
+ $byte->decoded(); // returns 'füü'
245
+ $byte->encoded(); // returns 'f%c3%bc%c3%bc'
246
+
247
+ $displayString = ByteSequence::fromDecoded('Hello world!');
240
248
$byte->decoded(); // returns 'Hello world!'
241
249
$byte->encoded(); // returns 'SGVsbG8gd29ybGQh'
242
250
243
251
$token->equals($byte); // will return false;
252
+ $displayString->equals($byte); // will return false;
244
253
$byte->equals(ByteSequence::fromEncoded('SGVsbG8gd29ybGQh')); // will return true
245
254
246
255
$token->type(); // returns Type::Token enum
247
256
$byte->type(); // returns Type::ByteSequence
257
+ $displayString->type(); // returns Type::DisplayString
248
258
```
249
259
250
260
> [ !WARNING]
251
- > Both classes DO NOT expose the ` Stringable ` interface to distinguish them
261
+ > The classes DO NOT expose the ` Stringable ` interface to distinguish them
252
262
from a string or a string like object
253
263
254
264
#### Item
@@ -316,11 +326,11 @@ use Bakame\Http\StructuredFields\InnerList;
316
326
use Bakame\Http\StructuredFields\Item;
317
327
use Bakame\Http\StructuredFields\Parameters;
318
328
319
- $field->parameter(string $key): ByteSequence|Token|DateTimeImmutable|Stringable|string|int|float|bool|null;
329
+ $field->parameter(string $key): ByteSequence|Token|DisplayString| DateTimeImmutable|Stringable|string|int|float|bool|null;
320
330
$field->parameters(): Parameters;
321
- $field->parameterByIndex(int $index): array{0:string, 1:ByteSequence|Token|DateTimeImmutable|Stringable|string|int|float|boo}|array{}
331
+ $field->parameterByIndex(int $index): array{0:string, 1:ByteSequence|Token|DisplayString| DateTimeImmutable|Stringable|string|int|float|boo}|array{}
322
332
InnerList::toPair(): array{0:list<Item >, 1:Parameters}>};
323
- Item::toPair(): array{0:ByteSequence|Token|DateTimeImmutable|Stringable|string|int|float|bool, 1:Parameters}>};
333
+ Item::toPair(): array{0:ByteSequence|Token|DisplayString| DateTimeImmutable|Stringable|string|int|float|bool, 1:Parameters}>};
324
334
```
325
335
326
336
> [ !NOTE]
@@ -343,8 +353,10 @@ use Bakame\Http\StructuredFields\ByteSequence;
343
353
use Bakame\Http\StructuredFields\Item;
344
354
use Bakame\Http\StructuredFields\Token;
345
355
346
- Item:new(DateTimeInterface|ByteSequence|Token|string|int|float|bool $value): self
356
+ Item:new(DateTimeInterface|ByteSequence|Token|DisplayString| string|int|float|bool $value): self
347
357
Item::fromDecodedByteSequence(Stringable|string $value): self;
358
+ Item::fromEncodedDisplayString(Stringable|string $value): self;
359
+ Item::fromDecodedDisplayString(Stringable|string $value): self;
348
360
Item::fromEncodedByteSequence(Stringable|string $value): self;
349
361
Item::fromToken(Stringable|string $value): self;
350
362
Item::fromString(Stringable|string $value): self;
@@ -363,7 +375,7 @@ To update the `Item` instance value, use the `withValue` method:
363
375
``` php
364
376
use Bakame\Http\StructuredFields\Item;
365
377
366
- Item::withValue(DateTimeInterface|ByteSequence|Token|string|int|float|bool $value): static
378
+ Item::withValue(DateTimeInterface|ByteSequence|Token|DisplayString| string|int|float|bool $value): static
367
379
```
368
380
369
381
#### Ordered Maps
0 commit comments