Skip to content

Commit

Permalink
add support for immutable 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Sep 23, 2023
1 parent 83a8a2b commit 0d00e39
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 32 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
## 4.3.0 - 2023-09-23

### Added

- Support for `innmind/immutable:~5.0`

### Removed

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require": {
"php": "~8.2",
"innmind/immutable": "~4.6",
"innmind/immutable": "~4.15|~5.0",
"innmind/time-continuum": "~3.1",
"innmind/math": "~6.0",
"innmind/url": "~4.1",
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Basic/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class Message
private function __construct(Sequence $chunks, int $length)
{
$this->chunks = $chunks->map(
static fn($chunk) => $chunk->toEncoding('ASCII'),
static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii),
);
$this->length = $length;
/** @var Map<string, mixed> */
Expand Down Expand Up @@ -112,7 +112,7 @@ public static function of(Str $body): self
{
return new self(
Sequence::of($body),
$body->toEncoding('ASCII')->length(),
$body->toEncoding(Str\Encoding::ascii)->length(),
);
}

Expand All @@ -123,7 +123,7 @@ public static function of(Str $body): self
public static function file(Content $content): self
{
$chunks = (new Chunk)($content)->map(
static fn($chunk) => $chunk->toEncoding('ASCII'),
static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii),
);
/** @var int<0, max> */
$size = $content->size()->match(
Expand Down Expand Up @@ -355,7 +355,7 @@ public function body(): Str
return $this
->chunks
->fold(new Concat)
->toEncoding('ASCII');
->toEncoding(Str\Encoding::ascii);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private function sendFrame(Frame $frame): Either
/** @var Either<Failure, self> */
return Maybe::just($frame)
->filter(fn($frame) => $this->maxChannels->allows($frame->channel()->toInt()))
->map(static fn($frame) => $frame->pack()->toEncoding('ASCII'))
->map(static fn($frame) => $frame->pack()->toEncoding(Str\Encoding::ascii))
->filter(fn($frame) => $this->maxFrameSize->allows($frame->length()))
->flatMap(
fn($frame) => $this
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Connection/MessageReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private function accumulateChunk(
return $frame
->content()
->either()
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->flatMap(
static fn($chunk) => $stream
->write($chunk)
Expand Down
8 changes: 4 additions & 4 deletions src/Transport/Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private function packMethod(): Str
->values
->map(static fn($value) => $value->pack())
->fold(new Concat)
->toEncoding('ASCII');
->toEncoding(Str\Encoding::ascii);

return $this->doPack($payload);
}
Expand All @@ -185,7 +185,7 @@ private function packHeader(): Str
->values
->map(static fn($value) => $value->pack())
->fold(new Concat)
->toEncoding('ASCII');
->toEncoding(Str\Encoding::ascii);

return $this->doPack($payload);
}
Expand All @@ -207,7 +207,7 @@ private function packHeartbeat(): Str

private function doPack(Str $payload): Str
{
$payload = $payload->toEncoding('ASCII');
$payload = $payload->toEncoding(Str\Encoding::ascii);

/** @psalm-suppress InvalidArgument */
return Sequence::of(
Expand All @@ -218,6 +218,6 @@ private function doPack(Str $payload): Str
UnsignedOctet::internal(self::end())->pack(),
)
->fold(new Concat)
->toEncoding('ASCII');
->toEncoding(Str\Encoding::ascii);
}
}
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/Bits.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(1)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 1)
->map(
static fn($chunk) => $chunk
Expand Down
6 changes: 3 additions & 3 deletions src/Transport/Frame/Value/LongString.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function literal(string $string): self
public static function of(Str $string): self
{
/** @psalm-suppress InvalidArgument */
$_ = UnsignedLongInteger::of($string->toEncoding('ASCII')->length());
$_ = UnsignedLongInteger::of($string->toEncoding(Str\Encoding::ascii)->length());

return new self($string);
}
Expand All @@ -55,7 +55,7 @@ public static function unpack(Readable $stream): Maybe
->flatMap(
static fn($length) => $stream
->read($length)
->map(static fn($string) => $string->toEncoding('ASCII'))
->map(static fn($string) => $string->toEncoding(Str\Encoding::ascii))
->filter(static fn($string) => $string->length() === $length),
)
->map(static fn($string) => new self($string));
Expand All @@ -75,7 +75,7 @@ public function pack(): Str
{
/** @psalm-suppress InvalidArgument */
return UnsignedLongInteger::of(
$this->original->toEncoding('ASCII')->length(),
$this->original->toEncoding(Str\Encoding::ascii)->length(),
)
->pack()
->append($this->original->toString());
Expand Down
4 changes: 2 additions & 2 deletions src/Transport/Frame/Value/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function pack(): Str
$value->pack(),
))
->fold(new Concat)
->toEncoding('ASCII');
->toEncoding(Str\Encoding::ascii);
/** @psalm-suppress InvalidArgument */
$value = UnsignedLongInteger::of($data->length())->pack();

Expand All @@ -105,7 +105,7 @@ private static function unpackNested(
): Maybe {
return $stream
->read(1)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 1)
->flatMap(static fn($chunk) => Symbol::unpack($clock, $chunk->toString(), $stream))
->flatMap(static fn($value) => match ($stream->position()->toInt() < $boundary) {
Expand Down
6 changes: 3 additions & 3 deletions src/Transport/Frame/Value/ShortString.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function literal(string $string): self
public static function of(Str $string): self
{
/** @psalm-suppress InvalidArgument */
$_ = UnsignedOctet::of($string->toEncoding('ASCII')->length());
$_ = UnsignedOctet::of($string->toEncoding(Str\Encoding::ascii)->length());

return new self($string);
}
Expand All @@ -55,7 +55,7 @@ public static function unpack(Readable $stream): Maybe
->flatMap(
static fn($length) => $stream
->read($length)
->map(static fn($string) => $string->toEncoding('ASCII'))
->map(static fn($string) => $string->toEncoding(Str\Encoding::ascii))
->filter(static fn($string) => $string->length() === $length),
)
->map(static fn($string) => new self($string));
Expand All @@ -75,7 +75,7 @@ public function pack(): Str
{
/** @psalm-suppress InvalidArgument */
return UnsignedOctet::of(
$this->original->toEncoding('ASCII')->length(),
$this->original->toEncoding(Str\Encoding::ascii)->length(),
)
->pack()
->append($this->original->toString());
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/SignedLongInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(4)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 4)
->map(static function($chunk) {
/** @var int<-2147483648, 2147483647> $value */
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/SignedLongLongInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(8)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 8)
->map(static function($chunk) {
/** @var int $value */
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/SignedOctet.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(1)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 1)
->map(static function($chunk) {
/** @var int<-128, 127> $value */
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/SignedShortInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(2)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 2)
->map(static function($chunk) {
/** @var int<-32768, 32767> $value */
Expand Down
4 changes: 2 additions & 2 deletions src/Transport/Frame/Value/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function pack(): Str
$pair[1]->pack(),
))
->fold(new Concat)
->toEncoding('ASCII');
->toEncoding(Str\Encoding::ascii);

/** @psalm-suppress InvalidArgument */
$value = UnsignedLongInteger::of($data->length())->pack();
Expand All @@ -113,7 +113,7 @@ private static function unpackNested(
->flatMap(
static fn($key) => $stream
->read(1)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 1)
->flatMap(static fn($chunk) => Symbol::unpack(
$clock,
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/UnsignedLongInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(4)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 4)
->map(static function($chunk) {
/** @var int<0, 4294967295> $value */
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/UnsignedLongLongInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(8)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 8)
->map(static function($chunk) {
/** @var int<0, max> $value */
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/UnsignedOctet.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(1)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 1)
->map(static function($chunk) {
/** @var int<0, 255> $octet */
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Frame/Value/UnsignedShortInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function unpack(Readable $stream): Maybe
{
return $stream
->read(2)
->map(static fn($chunk) => $chunk->toEncoding('ASCII'))
->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii))
->filter(static fn($chunk) => $chunk->length() === 2)
->map(static function($chunk) {
/** @var int<0, 65535> $value */
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Protocol/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function response(User $user, Password $password): LongString
$response = Table::of($arguments);
$response = $response
->pack()
->toEncoding('ASCII')
->toEncoding(Str\Encoding::ascii)
->substring(4); // skip the encoded table length integer

return LongString::of($response);
Expand Down

0 comments on commit 0d00e39

Please sign in to comment.