Skip to content

Commit 17e9e9b

Browse files
committed
Improve renaming ByteSequence class
1 parent 6c0f90a commit 17e9e9b

24 files changed

+109
-109
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
66

77
### Added
88

9-
- `Byte` class replace the `ByteSequence` class.
9+
- `Bytes` class replace the `ByteSequence` class.
1010
- `Ietf` enum.
1111
- methods `fromRFC9651`, `fromRfc8941`, `toRFC9651`, `toRfc8941`, to ease parsing/serializing Structured Fields.
1212
- method `equals` to allow comparison of Structured Fields values.
@@ -45,7 +45,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
4545
- `InnerList:remove` replaced by `InnerList:removeByIndices`
4646
- `::hasNoMember` and `::hasMembers` methods have been replaced by `isEmpty` and `isNotEmpty` on containers
4747
- `Dictionary::toPairs` and `Parameters::toPairs`
48-
- `ByteSequence` class replaced by `Byte` class
48+
- `ByteSequence` class replaced by `Bytes` class
4949

5050
## [1.3.0](https://github.com/bakame-php/http-structured-fields/compare/1.2.2...1.3.0) - 2024-01-05
5151

docs/03-field-values.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or provides a class based alternative. The table below summarizes the value type
1717
| String | `string` | `Type::String` | `string` | RFC8941 |
1818
| Boolean | `bool` | `Type::Boolean` | `boolean` | RFC8941 |
1919
| Token | class `Token` | `Type::Token` | `token` | RFC8941 |
20-
| Byte Sequence | class `Byte` | `Type::Byte` | `binary` | RFC8941 |
20+
| Byte Sequence | class `Bytes` | `Type::Bytes` | `binary` | RFC8941 |
2121
| Date | class `DateTimeImmutable` | `Type::Date` | `date` | RFC9651 |
2222
| DisplayString | class `DisplayString` | `Type::DisplayString` | `displaystring` | RFC9651 |
2323

@@ -73,13 +73,13 @@ PHP default type system, for them, we have defined three classes `Token`,
7373
`Byte` and `DisplayString` to help with their representation.
7474

7575
```php
76-
use Bakame\Http\StructuredFields\Byte;
76+
use Bakame\Http\StructuredFields\Bytes;
7777
use Bakame\Http\StructuredFields\DisplayString;
7878
use Bakame\Http\StructuredFields\Token;
7979

8080
Token::fromString(string|Stringable $value): Token
81-
Byte::fromDecoded(string|Stringable $value): Byte;
82-
Byte::fromEncoded(string|Stringable $value): Byte;
81+
Bytes::fromDecoded(string|Stringable $value): Byte;
82+
Bytes::fromEncoded(string|Stringable $value): Byte;
8383
DisplayString::fromDecoded(string|Stringable $value): DisplayString;
8484
DisplayString::fromEncoded(string|Stringable $value): DisplayString;
8585
```
@@ -89,7 +89,7 @@ instantiated. To access their value, they expose the following API:
8989

9090
```php
9191
use Bakame\Http\StructuredFields\Token;
92-
use Bakame\Http\StructuredFields\Byte;
92+
use Bakame\Http\StructuredFields\Bytes;
9393
use Bakame\Http\StructuredFields\DisplayString;
9494

9595
$token = Token::fromString('application/text+xml');
@@ -99,13 +99,13 @@ $displayString = DisplayString::fromDecoded('füü');
9999
$displayString->decoded(); // returns 'füü'
100100
$displayString->encoded(); // returns 'f%c3%bc%c3%bc'
101101

102-
$byte = Byte::fromDecoded('Hello world!');
102+
$byte = Bytes::fromDecoded('Hello world!');
103103
$byte->decoded(); // returns 'Hello world!'
104104
$byte->encoded(); // returns 'SGVsbG8gd29ybGQh'
105105

106106
$token->equals($byte); // will return false;
107107
$displayString->equals($byte); // will return false;
108-
$byte->equals(Byte::fromEncoded('SGVsbG8gd29ybGQh')); // will return true
108+
$byte->equals(Bytes::fromEncoded('SGVsbG8gd29ybGQh')); // will return true
109109
$displayString->equals(DisplayString::fromEncoded('f%c3%bc%c3%bc')); // will return true
110110

111111
$token->type(); // returns Type::Token
@@ -142,16 +142,16 @@ The `Item` value object exposes the following named constructors to instantiate
142142
bare items (ie: item without parameters attached to them).
143143

144144
```php
145-
use Bakame\Http\StructuredFields\Byte;
145+
use Bakame\Http\StructuredFields\Bytes;
146146
use Bakame\Http\StructuredFields\Item;
147147
use Bakame\Http\StructuredFields\Token;
148148

149149
Item:new(DateTimeInterface|Byte|Token|DisplayString|string|int|array|float|bool $value): self
150150
Item:tryNew(mixed $value): ?self
151-
Item::fromDecodedByteSequence(Stringable|string $value): self;
151+
Item::fromDecodedBytes(Stringable|string $value): self;
152152
Item::fromEncodedDisplayString(Stringable|string $value): self;
153153
Item::fromDecodedDisplayString(Stringable|string $value): self;
154-
Item::fromEncodedByteSequence(Stringable|string $value): self;
154+
Item::fromEncodedBytes(Stringable|string $value): self;
155155
Item::fromToken(Stringable|string $value): self;
156156
Item::fromString(Stringable|string $value): self;
157157
Item::fromDate(DateTimeInterface $datetime): self;

docs/04-containers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ which takes a single variadic parameter `$members`:
274274

275275
```php
276276
use Bakame\Http\StructuredFields\InnerList;
277-
use Bakame\Http\StructuredFields\Byte;
277+
use Bakame\Http\StructuredFields\Bytes;
278278

279279
$list = InnerList::new(
280-
Byte::fromDecoded('Hello World'),
280+
Bytes::fromDecoded('Hello World'),
281281
42.0,
282282
42
283283
);
@@ -300,14 +300,14 @@ $list->removeByIndices(int ...$index): static;
300300
as shown below
301301

302302
```php
303-
use Bakame\Http\StructuredFields\Byte;
303+
use Bakame\Http\StructuredFields\Bytes;
304304
use Bakame\Http\StructuredFields\InnerList;
305305

306306
$list = InnerList::new()
307307
->unshift('42')
308308
->push(42)
309309
->insert(1, 42.0)
310-
->replace(0, Byte::fromDecoded('Hello World'));
310+
->replace(0, Bytes::fromDecoded('Hello World'));
311311

312312
echo $list->toHttpValue(); //'(:SGVsbG8gV29ybGQ=: 42.0 42)'
313313
echo $list; //'(:SGVsbG8gV29ybGQ=: 42.0 42)'
@@ -347,7 +347,7 @@ To ease working with instances that have a `Parameters` object attached to, the
347347
methods are added:
348348

349349
```php
350-
use Bakame\Http\StructuredFields\Byte;
350+
use Bakame\Http\StructuredFields\Bytes;
351351
use Bakame\Http\StructuredFields\InnerList;
352352
use Bakame\Http\StructuredFields\Item;
353353
use Bakame\Http\StructuredFields\Token;

src/Byte.php renamed to src/Bytes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @see https://www.rfc-editor.org/rfc/rfc9651.html#section-3.3.5
1616
*/
17-
final class Byte
17+
final class Bytes
1818
{
1919
private function __construct(
2020
private readonly string $value
@@ -79,6 +79,6 @@ public function equals(mixed $other): bool
7979

8080
public function type(): Type
8181
{
82-
return Type::ByteSequence;
82+
return Type::Bytes;
8383
}
8484
}

src/Dictionary.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public function last(): array
493493
*/
494494
public function add(
495495
string $name,
496-
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
496+
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
497497
): self {
498498
if (null === $member) {
499499
return $this;
@@ -583,7 +583,7 @@ public function removeByNames(string ...$names): self
583583
*/
584584
public function append(
585585
string $name,
586-
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
586+
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
587587
): self {
588588
if (null === $member) {
589589
return $this;
@@ -606,7 +606,7 @@ public function append(
606606
*/
607607
public function prepend(
608608
string $name,
609-
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
609+
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
610610
): self {
611611
if (null === $member) {
612612
return $this;

src/InnerList.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static function fromPair(array $pair): self
113113
* Returns a new instance.
114114
*/
115115
public static function new(
116-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
116+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
117117
): self {
118118
return new self($members, Parameters::new());
119119
}
@@ -258,7 +258,7 @@ public function withParameters(Parameters $parameters): static
258258
* Inserts members at the beginning of the list.
259259
*/
260260
public function unshift(
261-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
261+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
262262
): self {
263263
$membersToAdd = array_reduce(
264264
$members,
@@ -282,7 +282,7 @@ function (array $carry, $member) {
282282
* Inserts members at the end of the list.
283283
*/
284284
public function push(
285-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
285+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
286286
): self {
287287
$membersToAdd = array_reduce(
288288
$members,
@@ -309,7 +309,7 @@ function (array $carry, $member) {
309309
*/
310310
public function insert(
311311
int $index,
312-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
312+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
313313
): self {
314314
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);
315315

@@ -327,7 +327,7 @@ public function insert(
327327

328328
public function replace(
329329
int $index,
330-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool $member
330+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool $member
331331
): self {
332332
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);
333333
$member = self::filterMember($member);

src/Item.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function fromHttpValue(Stringable|string $httpValue, ?Ietf $rfc =
6161
*
6262
* @throws SyntaxError If the value or the parameters are not valid
6363
*/
64-
public static function fromAssociative(Byte|Token|DisplayString|DateTimeInterface|string|int|float|bool $value, iterable $parameters): self
64+
public static function fromAssociative(Bytes|Token|DisplayString|DateTimeInterface|string|int|float|bool $value, iterable $parameters): self
6565
{
6666
if (!$parameters instanceof Parameters) {
6767
$parameters = Parameters::fromAssociative($parameters);
@@ -138,19 +138,19 @@ public static function fromString(Stringable|string $value): self
138138
*
139139
* @throws SyntaxError if the sequence is invalid
140140
*/
141-
public static function fromEncodedByteSequence(Stringable|string $value): self
141+
public static function fromEncodedBytes(Stringable|string $value): self
142142
{
143-
return self::fromValue(Value::fromEncodedByteSequence($value));
143+
return self::fromValue(Value::fromEncodedBytes($value));
144144
}
145145

146146
/**
147147
* Returns a new instance from a decoded byte sequence and an iterable of key-value parameters.
148148
*
149149
* @throws SyntaxError if the sequence is invalid
150150
*/
151-
public static function fromDecodedByteSequence(Stringable|string $value): self
151+
public static function fromDecodedBytes(Stringable|string $value): self
152152
{
153-
return self::fromValue(Value::fromDecodedByteSequence($value));
153+
return self::fromValue(Value::fromDecodedBytes($value));
154154
}
155155

156156
/**
@@ -270,7 +270,7 @@ public static function false(): self
270270
*
271271
* @throws Violation
272272
*/
273-
public function value(?callable $validate = null): Byte|Token|DisplayString|DateTimeImmutable|string|int|float|bool
273+
public function value(?callable $validate = null): Bytes|Token|DisplayString|DateTimeImmutable|string|int|float|bool
274274
{
275275
$value = $this->value->value;
276276
if (null === $validate) {
@@ -343,7 +343,7 @@ public function equals(mixed $other): bool
343343
* @throws SyntaxError If the value is invalid or not supported
344344
*/
345345
public function withValue(
346-
DateTimeInterface|Byte|Token|DisplayString|string|int|float|bool $value
346+
DateTimeInterface|Bytes|Token|DisplayString|string|int|float|bool $value
347347
): self {
348348
$value = new Value($value);
349349
if ($value->equals($this->value)) {

src/OuterList.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class OuterList implements ArrayAccess, Countable, IteratorAggregate
4545
* @param InnerList|Item|SfMemberInput ...$members
4646
*/
4747
private function __construct(
48-
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
48+
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
4949
) {
5050
$this->members = array_map($this->filterMember(...), array_values([...$members]));
5151
}
@@ -145,7 +145,7 @@ public static function fromPairs(StructuredFieldProvider|iterable $pairs): self
145145
/**
146146
* @param InnerList|Item|SfMemberInput ...$members
147147
*/
148-
public static function new(iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members): self
148+
public static function new(iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members): self
149149
{
150150
return new self(...$members);
151151
}
@@ -279,7 +279,7 @@ public function last(): InnerList|Item|null
279279
* @param StructuredFieldProvider|InnerList|Item|SfMemberInput ...$members
280280
*/
281281
public function unshift(
282-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|iterable|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
282+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|iterable|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
283283
): self {
284284
$membersToAdd = array_reduce(
285285
$members,
@@ -305,7 +305,7 @@ function (array $carry, $member) {
305305
* @param InnerList|Item|SfMemberInput ...$members
306306
*/
307307
public function push(
308-
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
308+
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
309309
): self {
310310
$membersToAdd = array_reduce(
311311
$members,
@@ -334,7 +334,7 @@ function (array $carry, $member) {
334334
*/
335335
public function insert(
336336
int $index,
337-
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
337+
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
338338
): self {
339339
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);
340340

@@ -355,7 +355,7 @@ public function insert(
355355
*/
356356
public function replace(
357357
int $index,
358-
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool $member
358+
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool $member
359359
): self {
360360
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);
361361
$member = self::filterMember($member);

src/ParameterAccess.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function parameterByName(
3838
string $name,
3939
?callable $validate = null,
4040
bool|string $required = false,
41-
Byte|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null $default = null
42-
): Byte|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null {
41+
Bytes|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null $default = null
42+
): Bytes|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null {
4343
return $this->parameters->valueByName($name, $validate, $required, $default);
4444
}
4545

@@ -82,7 +82,7 @@ abstract public function withParameters(Parameters $parameters): static;
8282
*/
8383
public function addParameter(
8484
string $name,
85-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
85+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
8686
): static {
8787
return $this->withParameters($this->parameters()->add($name, $member));
8888
}
@@ -99,7 +99,7 @@ public function addParameter(
9999
*/
100100
public function prependParameter(
101101
string $name,
102-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
102+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
103103
): static {
104104
return $this->withParameters($this->parameters()->prepend($name, $member));
105105
}
@@ -116,7 +116,7 @@ public function prependParameter(
116116
*/
117117
public function appendParameter(
118118
string $name,
119-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
119+
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
120120
): static {
121121
return $this->withParameters($this->parameters()->append($name, $member));
122122
}

0 commit comments

Comments
 (0)