Skip to content

Commit b052081

Browse files
committed
Update the documentation to add the DisplayString class
1 parent 1ec8f4c commit b052081

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

README.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,16 @@ Per the RFC, items can have different types that are translated to PHP using:
176176

177177
The table below summarizes the item value type.
178178

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` |
188189

189190
The Enum `Type` which list all available types can be use to determine the RFC type
190191
corresponding to a PHP structure using the `Type::fromValue` static method.
@@ -213,9 +214,9 @@ Type::String->equals($field); // returns true;
213214
Type::Boolean->equals(Type::String); // returns false
214215
```
215216

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.
219220

220221
```php
221222
use Bakame\Http\StructuredFields\Token;
@@ -224,31 +225,40 @@ use Bakame\Http\StructuredFields\ByteSequence;
224225
Token::fromString(string|Stringable $value): Token
225226
ByteSequence::fromDecoded(string|Stringable $value): ByteSequence;
226227
ByteSequence::fromEncoded(string|Stringable $value): ByteSequence;
228+
DisplayString::fromDecoded(string|Stringable $value): DisplayString;
229+
DisplayString::fromEncoded(string|Stringable $value): DisplayString;
227230
```
228231

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
230233
instantiated. To access their value, they expose the following API:
231234

232235
```php
233236
use Bakame\Http\StructuredFields\Token;
234237
use Bakame\Http\StructuredFields\ByteSequence;
238+
use Bakame\Http\StructuredFields\DisplayString;
235239

236240
$token = Token::fromString('application/text+xml');
237241
echo $token->toString(); // returns 'application/text+xml'
238242

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!');
240248
$byte->decoded(); // returns 'Hello world!'
241249
$byte->encoded(); // returns 'SGVsbG8gd29ybGQh'
242250

243251
$token->equals($byte); // will return false;
252+
$displayString->equals($byte); // will return false;
244253
$byte->equals(ByteSequence::fromEncoded('SGVsbG8gd29ybGQh')); // will return true
245254

246255
$token->type(); // returns Type::Token enum
247256
$byte->type(); // returns Type::ByteSequence
257+
$displayString->type(); // returns Type::DisplayString
248258
```
249259

250260
> [!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
252262
from a string or a string like object
253263

254264
#### Item
@@ -316,11 +326,11 @@ use Bakame\Http\StructuredFields\InnerList;
316326
use Bakame\Http\StructuredFields\Item;
317327
use Bakame\Http\StructuredFields\Parameters;
318328

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;
320330
$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{}
322332
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}>};
324334
```
325335

326336
> [!NOTE]
@@ -343,8 +353,10 @@ use Bakame\Http\StructuredFields\ByteSequence;
343353
use Bakame\Http\StructuredFields\Item;
344354
use Bakame\Http\StructuredFields\Token;
345355

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
347357
Item::fromDecodedByteSequence(Stringable|string $value): self;
358+
Item::fromEncodedDisplayString(Stringable|string $value): self;
359+
Item::fromDecodedDisplayString(Stringable|string $value): self;
348360
Item::fromEncodedByteSequence(Stringable|string $value): self;
349361
Item::fromToken(Stringable|string $value): self;
350362
Item::fromString(Stringable|string $value): self;
@@ -363,7 +375,7 @@ To update the `Item` instance value, use the `withValue` method:
363375
```php
364376
use Bakame\Http\StructuredFields\Item;
365377

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
367379
```
368380

369381
#### Ordered Maps

0 commit comments

Comments
 (0)