Skip to content

Commit 66815d9

Browse files
committed
Adding missing Item::fromString named constructor
1 parent 9ad0ea7 commit 66815d9

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
1313
- `Item::toPair` to complement `Item::fromPair`;
1414
- `Item::fromDate` to improve and complete the Item Date public API;
1515
- `Item::fromAssociative` to improve Item public API;
16+
- `Item::fromString` to improve Item public API;
1617
- `Value` internal class to improve Item public API;
1718
- `Token::toString` to return the string representation of the token.
1819

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,10 @@ bare items (ie: item without parameters attached to them).
218218
```php
219219
use Bakame\Http\StructuredFields\Item;
220220

221-
Item::fromDecodedByteSequence(string $value): self;
222-
Item::fromEncodedByteSequence(string $value): self;
223-
Item::fromToken(string $value): self;
221+
Item::fromDecodedByteSequence(Stringable|string $value): self;
222+
Item::fromEncodedByteSequence(Stringable|string $value): self;
223+
Item::fromToken(Stringable|string $value): self;
224+
Item::fromString(Stringable|string $value): self;
224225
Item::fromTimestamp(int $value): self;
225226
Item::fromDateFormat(string $format, string $datetime): self;
226227
Item::fromDateString(string $datetime, DateTimeZone|string|null $timezone = null): self;

src/Item.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ private static function fromValue(Value $value): self
9797
return new self($value, Parameters::create());
9898
}
9999

100+
/**
101+
* Returns a new instance from a string.
102+
*/
103+
public static function fromString(Stringable|string $value): self
104+
{
105+
return self::fromValue(Value::fromString($value));
106+
}
107+
100108
/**
101109
* Returns a new instance from an encoded byte sequence and an iterable of key-value parameters.
102110
*/

src/ItemTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function it_instantiates_a_binary(): void
243243
#[Test]
244244
public function it_instantiates_a_string(): void
245245
{
246-
self::assertSame('"foobar"', Item::fromAssociative('foobar')->toHttpValue());
246+
self::assertSame('"foobar"', Item::fromString('foobar')->toHttpValue());
247247
}
248248

249249
#[Test]

src/Value.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ public static function fromInteger(int|float $value): self
182182
return new self((int) $value);
183183
}
184184

185+
public static function fromString(Stringable|string $value): self
186+
{
187+
return new self($value);
188+
}
189+
185190
public static function true(): self
186191
{
187192
return new self(true);

0 commit comments

Comments
 (0)