Skip to content

Commit

Permalink
Improve renaming ByteSequence class
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 19, 2024
1 parent 6c0f90a commit 17e9e9b
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 109 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this

### Added

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

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

Expand Down
20 changes: 10 additions & 10 deletions docs/03-field-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ or provides a class based alternative. The table below summarizes the value type
| String | `string` | `Type::String` | `string` | RFC8941 |
| Boolean | `bool` | `Type::Boolean` | `boolean` | RFC8941 |
| Token | class `Token` | `Type::Token` | `token` | RFC8941 |
| Byte Sequence | class `Byte` | `Type::Byte` | `binary` | RFC8941 |
| Byte Sequence | class `Bytes` | `Type::Bytes` | `binary` | RFC8941 |
| Date | class `DateTimeImmutable` | `Type::Date` | `date` | RFC9651 |
| DisplayString | class `DisplayString` | `Type::DisplayString` | `displaystring` | RFC9651 |

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

```php
use Bakame\Http\StructuredFields\Byte;
use Bakame\Http\StructuredFields\Bytes;
use Bakame\Http\StructuredFields\DisplayString;
use Bakame\Http\StructuredFields\Token;

Token::fromString(string|Stringable $value): Token
Byte::fromDecoded(string|Stringable $value): Byte;
Byte::fromEncoded(string|Stringable $value): Byte;
Bytes::fromDecoded(string|Stringable $value): Byte;
Bytes::fromEncoded(string|Stringable $value): Byte;
DisplayString::fromDecoded(string|Stringable $value): DisplayString;
DisplayString::fromEncoded(string|Stringable $value): DisplayString;
```
Expand All @@ -89,7 +89,7 @@ instantiated. To access their value, they expose the following API:

```php
use Bakame\Http\StructuredFields\Token;
use Bakame\Http\StructuredFields\Byte;
use Bakame\Http\StructuredFields\Bytes;
use Bakame\Http\StructuredFields\DisplayString;

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

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

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

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

```php
use Bakame\Http\StructuredFields\Byte;
use Bakame\Http\StructuredFields\Bytes;
use Bakame\Http\StructuredFields\Item;
use Bakame\Http\StructuredFields\Token;

Item:new(DateTimeInterface|Byte|Token|DisplayString|string|int|array|float|bool $value): self
Item:tryNew(mixed $value): ?self
Item::fromDecodedByteSequence(Stringable|string $value): self;
Item::fromDecodedBytes(Stringable|string $value): self;
Item::fromEncodedDisplayString(Stringable|string $value): self;
Item::fromDecodedDisplayString(Stringable|string $value): self;
Item::fromEncodedByteSequence(Stringable|string $value): self;
Item::fromEncodedBytes(Stringable|string $value): self;
Item::fromToken(Stringable|string $value): self;
Item::fromString(Stringable|string $value): self;
Item::fromDate(DateTimeInterface $datetime): self;
Expand Down
10 changes: 5 additions & 5 deletions docs/04-containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ which takes a single variadic parameter `$members`:

```php
use Bakame\Http\StructuredFields\InnerList;
use Bakame\Http\StructuredFields\Byte;
use Bakame\Http\StructuredFields\Bytes;

$list = InnerList::new(
Byte::fromDecoded('Hello World'),
Bytes::fromDecoded('Hello World'),
42.0,
42
);
Expand All @@ -300,14 +300,14 @@ $list->removeByIndices(int ...$index): static;
as shown below

```php
use Bakame\Http\StructuredFields\Byte;
use Bakame\Http\StructuredFields\Bytes;
use Bakame\Http\StructuredFields\InnerList;

$list = InnerList::new()
->unshift('42')
->push(42)
->insert(1, 42.0)
->replace(0, Byte::fromDecoded('Hello World'));
->replace(0, Bytes::fromDecoded('Hello World'));

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

```php
use Bakame\Http\StructuredFields\Byte;
use Bakame\Http\StructuredFields\Bytes;
use Bakame\Http\StructuredFields\InnerList;
use Bakame\Http\StructuredFields\Item;
use Bakame\Http\StructuredFields\Token;
Expand Down
4 changes: 2 additions & 2 deletions src/Byte.php → src/Bytes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @see https://www.rfc-editor.org/rfc/rfc9651.html#section-3.3.5
*/
final class Byte
final class Bytes
{
private function __construct(
private readonly string $value
Expand Down Expand Up @@ -79,6 +79,6 @@ public function equals(mixed $other): bool

public function type(): Type
{
return Type::ByteSequence;
return Type::Bytes;
}
}
6 changes: 3 additions & 3 deletions src/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public function last(): array
*/
public function add(
string $name,
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
): self {
if (null === $member) {
return $this;
Expand Down Expand Up @@ -583,7 +583,7 @@ public function removeByNames(string ...$names): self
*/
public function append(
string $name,
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
): self {
if (null === $member) {
return $this;
Expand All @@ -606,7 +606,7 @@ public function append(
*/
public function prepend(
string $name,
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
): self {
if (null === $member) {
return $this;
Expand Down
10 changes: 5 additions & 5 deletions src/InnerList.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function fromPair(array $pair): self
* Returns a new instance.
*/
public static function new(
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
): self {
return new self($members, Parameters::new());
}
Expand Down Expand Up @@ -258,7 +258,7 @@ public function withParameters(Parameters $parameters): static
* Inserts members at the beginning of the list.
*/
public function unshift(
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
): self {
$membersToAdd = array_reduce(
$members,
Expand All @@ -282,7 +282,7 @@ function (array $carry, $member) {
* Inserts members at the end of the list.
*/
public function push(
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
): self {
$membersToAdd = array_reduce(
$members,
Expand All @@ -309,7 +309,7 @@ function (array $carry, $member) {
*/
public function insert(
int $index,
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
): self {
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);

Expand All @@ -327,7 +327,7 @@ public function insert(

public function replace(
int $index,
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool $member
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool $member
): self {
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);
$member = self::filterMember($member);
Expand Down
14 changes: 7 additions & 7 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function fromHttpValue(Stringable|string $httpValue, ?Ietf $rfc =
*
* @throws SyntaxError If the value or the parameters are not valid
*/
public static function fromAssociative(Byte|Token|DisplayString|DateTimeInterface|string|int|float|bool $value, iterable $parameters): self
public static function fromAssociative(Bytes|Token|DisplayString|DateTimeInterface|string|int|float|bool $value, iterable $parameters): self
{
if (!$parameters instanceof Parameters) {
$parameters = Parameters::fromAssociative($parameters);
Expand Down Expand Up @@ -138,19 +138,19 @@ public static function fromString(Stringable|string $value): self
*
* @throws SyntaxError if the sequence is invalid
*/
public static function fromEncodedByteSequence(Stringable|string $value): self
public static function fromEncodedBytes(Stringable|string $value): self
{
return self::fromValue(Value::fromEncodedByteSequence($value));
return self::fromValue(Value::fromEncodedBytes($value));
}

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

/**
Expand Down Expand Up @@ -270,7 +270,7 @@ public static function false(): self
*
* @throws Violation
*/
public function value(?callable $validate = null): Byte|Token|DisplayString|DateTimeImmutable|string|int|float|bool
public function value(?callable $validate = null): Bytes|Token|DisplayString|DateTimeImmutable|string|int|float|bool
{
$value = $this->value->value;
if (null === $validate) {
Expand Down Expand Up @@ -343,7 +343,7 @@ public function equals(mixed $other): bool
* @throws SyntaxError If the value is invalid or not supported
*/
public function withValue(
DateTimeInterface|Byte|Token|DisplayString|string|int|float|bool $value
DateTimeInterface|Bytes|Token|DisplayString|string|int|float|bool $value
): self {
$value = new Value($value);
if ($value->equals($this->value)) {
Expand Down
12 changes: 6 additions & 6 deletions src/OuterList.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class OuterList implements ArrayAccess, Countable, IteratorAggregate
* @param InnerList|Item|SfMemberInput ...$members
*/
private function __construct(
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
) {
$this->members = array_map($this->filterMember(...), array_values([...$members]));
}
Expand Down Expand Up @@ -145,7 +145,7 @@ public static function fromPairs(StructuredFieldProvider|iterable $pairs): self
/**
* @param InnerList|Item|SfMemberInput ...$members
*/
public static function new(iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members): self
public static function new(iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members): self
{
return new self(...$members);
}
Expand Down Expand Up @@ -279,7 +279,7 @@ public function last(): InnerList|Item|null
* @param StructuredFieldProvider|InnerList|Item|SfMemberInput ...$members
*/
public function unshift(
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|iterable|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|iterable|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
): self {
$membersToAdd = array_reduce(
$members,
Expand All @@ -305,7 +305,7 @@ function (array $carry, $member) {
* @param InnerList|Item|SfMemberInput ...$members
*/
public function push(
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
): self {
$membersToAdd = array_reduce(
$members,
Expand Down Expand Up @@ -334,7 +334,7 @@ function (array $carry, $member) {
*/
public function insert(
int $index,
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool ...$members
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
): self {
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);

Expand All @@ -355,7 +355,7 @@ public function insert(
*/
public function replace(
int $index,
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool $member
iterable|StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool $member
): self {
$offset = $this->filterIndex($index) ?? throw InvalidOffset::dueToIndexNotFound($index);
$member = self::filterMember($member);
Expand Down
10 changes: 5 additions & 5 deletions src/ParameterAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function parameterByName(
string $name,
?callable $validate = null,
bool|string $required = false,
Byte|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null $default = null
): Byte|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null {
Bytes|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null $default = null
): Bytes|Token|DisplayString|DateTimeImmutable|string|int|float|bool|null {
return $this->parameters->valueByName($name, $validate, $required, $default);
}

Expand Down Expand Up @@ -82,7 +82,7 @@ abstract public function withParameters(Parameters $parameters): static;
*/
public function addParameter(
string $name,
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
): static {
return $this->withParameters($this->parameters()->add($name, $member));
}
Expand All @@ -99,7 +99,7 @@ public function addParameter(
*/
public function prependParameter(
string $name,
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
): static {
return $this->withParameters($this->parameters()->prepend($name, $member));
}
Expand All @@ -116,7 +116,7 @@ public function prependParameter(
*/
public function appendParameter(
string $name,
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Byte|DisplayString|DateTimeInterface|string|int|float|bool|null $member
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool|null $member
): static {
return $this->withParameters($this->parameters()->append($name, $member));
}
Expand Down
Loading

0 comments on commit 17e9e9b

Please sign in to comment.