From aa843dd99118a8eee42faedf66ad776bb58b204b Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 23 Aug 2026 16:45:44 +0200 Subject: [PATCH 1/2] add Config::mapIO() --- CHANGELOG.md | 6 +++++ src/Config.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 278d983..659700d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Added + +- `Innmind\OperatingSystem\Config::mapIO()` + ## 7.2.0 - 2026-08-16 ### Changed diff --git a/src/Config.php b/src/Config.php index b7d7b77..c0ef7f6 100644 --- a/src/Config.php +++ b/src/Config.php @@ -35,6 +35,7 @@ final class Config * @psalm-mutation-free * * @param \Closure(Clock, self): Clock $mapClock + * @param \Closure(IO, self): IO $mapIO * @param \Closure(Halt, self): Halt $mapHalt * @param \Closure(HttpTransport, self): HttpTransport $mapHttpTransport * @param \Closure(Url): Attempt $sql @@ -49,6 +50,7 @@ private function __construct( private Clock $clock, private \Closure $mapClock, private IO $io, + private \Closure $mapIO, private Halt $halt, private \Closure $mapHalt, private EnvironmentPath $path, @@ -75,6 +77,7 @@ public static function new(): self Clock::live(), static fn(Clock $clock) => $clock, IO::fromAmbientAuthority(), + static fn(IO $io, self $config) => $io, Halt::new(), static fn(Halt $halt, self $config) => $halt, EnvironmentPath::of(match ($path = \getenv('PATH')) { @@ -123,6 +126,7 @@ public function withClock(Clock $clock): self $clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -159,6 +163,7 @@ public function mapClock(\Closure $map): self $config, ), $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -188,6 +193,7 @@ public function haltProcessVia(Halt $halt): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $halt, $this->mapHalt, $this->path, @@ -222,6 +228,7 @@ public function mapHalt(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, static fn(Halt $halt, self $config) => $map( $previous($halt, $config), @@ -254,6 +261,45 @@ public function withIO(IO $io): self $this->clock, $this->mapClock, $io, + $this->mapIO, + $this->halt, + $this->mapHalt, + $this->path, + $this->httpTransport, + $this->mapHttpTransport, + $this->sql, + $this->mapSql, + $this->serverControl, + $this->mapServerControl, + $this->serverStatus, + $this->mapServerStatus, + $this->watch, + $this->mapFileWatch, + $this->filesystem, + $this->mapFilesystem, + $this->signals, + ); + } + + /** + * @psalm-mutation-free + * + * @param \Closure(IO, self): IO $map + */ + #[\NoDiscard] + public function mapIO(\Closure $map): self + { + $previous = $this->mapIO; + + /** @psalm-suppress ImpureFunctionCall */ + return new self( + $this->clock, + $this->mapClock, + $this->io, + static fn(IO $io, self $config) => $map( + $previous($io, $config), + $config, + ), $this->halt, $this->mapHalt, $this->path, @@ -283,6 +329,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $path, @@ -312,6 +359,7 @@ public function useHttpTransport(HttpTransport $transport): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -345,6 +393,7 @@ public function mapHttpTransport(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -379,6 +428,7 @@ public function openSQLConnectionVia(\Closure $sql): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -412,6 +462,7 @@ public function mapSQLConnection(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -444,6 +495,7 @@ public function useServerControl(Control\Server $server): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -477,6 +529,7 @@ public function mapServerControl(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -509,6 +562,7 @@ public function useServerStatus(Status\Server $server): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -542,6 +596,7 @@ public function mapServerStatus(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -574,6 +629,7 @@ public function useFileWatch(Watch $watch): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -607,6 +663,7 @@ public function mapFileWatch(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -641,6 +698,7 @@ public function mountFilesystemVia(\Closure $filesystem): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -674,6 +732,7 @@ public function mapFilesystem(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -706,6 +765,7 @@ public function handleSignalsVia(Handler $handler): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -765,7 +825,7 @@ public function filesystem(Path $path): Attempt #[\NoDiscard] public function io(): IO { - return $this->io; + return ($this->mapIO)($this->io, $this); } /** From fc45fe268490172045a62e66081a9e9282212849 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 23 Aug 2026 16:53:38 +0200 Subject: [PATCH 2/2] add Config::mapSignalsHandler() --- CHANGELOG.md | 1 + src/Config.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 659700d..75b7eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - `Innmind\OperatingSystem\Config::mapIO()` +- `Innmind\OperatingSystem\Config::mapSignalsHandler()` ## 7.2.0 - 2026-08-16 diff --git a/src/Config.php b/src/Config.php index c0ef7f6..62e3aa3 100644 --- a/src/Config.php +++ b/src/Config.php @@ -45,6 +45,7 @@ final class Config * @param \Closure(Watch, self): Watch $mapFileWatch * @param \Closure(Path, self): Attempt $filesystem * @param \Closure(Filesystem, self): Filesystem $mapFilesystem + * @param \Closure(Handler, self): Handler $mapSignals */ private function __construct( private Clock $clock, @@ -67,6 +68,7 @@ private function __construct( private \Closure $filesystem, private \Closure $mapFilesystem, private Handler $signals, + private \Closure $mapSignals, ) { } @@ -101,6 +103,7 @@ public static function new(): self ), static fn(Filesystem $filesystem, self $config) => $filesystem, Handler::main(), + static fn(Handler $signals, self $config) => $signals, ); } @@ -143,6 +146,7 @@ public function withClock(Clock $clock): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -180,6 +184,7 @@ public function mapClock(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -210,6 +215,7 @@ public function haltProcessVia(Halt $halt): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -248,6 +254,7 @@ public function mapHalt(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -278,6 +285,7 @@ public function withIO(IO $io): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -316,6 +324,7 @@ public function mapIO(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -346,6 +355,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -376,6 +386,7 @@ public function useHttpTransport(HttpTransport $transport): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -413,6 +424,7 @@ public function mapHttpTransport(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -445,6 +457,7 @@ public function openSQLConnectionVia(\Closure $sql): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -482,6 +495,7 @@ public function mapSQLConnection(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -512,6 +526,7 @@ public function useServerControl(Control\Server $server): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -549,6 +564,7 @@ public function mapServerControl(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -579,6 +595,7 @@ public function useServerStatus(Status\Server $server): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -616,6 +633,7 @@ public function mapServerStatus(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -646,6 +664,7 @@ public function useFileWatch(Watch $watch): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -683,6 +702,7 @@ public function mapFileWatch(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -715,6 +735,7 @@ public function mountFilesystemVia(\Closure $filesystem): self $filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -752,6 +773,7 @@ public function mapFilesystem(\Closure $map): self $config, ), $this->signals, + $this->mapSignals, ); } @@ -782,6 +804,45 @@ public function handleSignalsVia(Handler $handler): self $this->filesystem, $this->mapFilesystem, $handler, + $this->mapSignals, + ); + } + + /** + * @psalm-mutation-free + * + * @param \Closure(Handler, self): Handler $map + */ + #[\NoDiscard] + public function mapSignalsHandler(\Closure $map): self + { + $previous = $this->mapSignals; + + return new self( + $this->clock, + $this->mapClock, + $this->io, + $this->mapIO, + $this->halt, + $this->mapHalt, + $this->path, + $this->httpTransport, + $this->mapHttpTransport, + $this->sql, + $this->mapSql, + $this->serverControl, + $this->mapServerControl, + $this->serverStatus, + $this->mapServerStatus, + $this->watch, + $this->mapFileWatch, + $this->filesystem, + $this->mapFilesystem, + $this->signals, + static fn(Handler $signals, self $config) => $map( + $previous($signals, $config), + $config, + ), ); } @@ -926,6 +987,6 @@ public function fileWatch(Control\Server\Processes $processes): Watch #[\NoDiscard] public function signalsHandler(): Handler { - return $this->signals; + return ($this->mapSignals)($this->signals, $this); } }