diff --git a/CHANGELOG.md b/CHANGELOG.md index 278d983..75b7eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [Unreleased] + +### Added + +- `Innmind\OperatingSystem\Config::mapIO()` +- `Innmind\OperatingSystem\Config::mapSignalsHandler()` + ## 7.2.0 - 2026-08-16 ### Changed diff --git a/src/Config.php b/src/Config.php index b7d7b77..62e3aa3 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 @@ -44,11 +45,13 @@ 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, private \Closure $mapClock, private IO $io, + private \Closure $mapIO, private Halt $halt, private \Closure $mapHalt, private EnvironmentPath $path, @@ -65,6 +68,7 @@ private function __construct( private \Closure $filesystem, private \Closure $mapFilesystem, private Handler $signals, + private \Closure $mapSignals, ) { } @@ -75,6 +79,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')) { @@ -98,6 +103,7 @@ public static function new(): self ), static fn(Filesystem $filesystem, self $config) => $filesystem, Handler::main(), + static fn(Handler $signals, self $config) => $signals, ); } @@ -123,6 +129,7 @@ public function withClock(Clock $clock): self $clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -139,6 +146,7 @@ public function withClock(Clock $clock): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -159,6 +167,7 @@ public function mapClock(\Closure $map): self $config, ), $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -175,6 +184,7 @@ public function mapClock(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -188,6 +198,7 @@ public function haltProcessVia(Halt $halt): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $halt, $this->mapHalt, $this->path, @@ -204,6 +215,7 @@ public function haltProcessVia(Halt $halt): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -222,6 +234,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), @@ -241,6 +254,7 @@ public function mapHalt(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -254,6 +268,7 @@ public function withIO(IO $io): self $this->clock, $this->mapClock, $io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -270,6 +285,46 @@ public function withIO(IO $io): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, + ); + } + + /** + * @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, + $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, + $this->mapSignals, ); } @@ -283,6 +338,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $path, @@ -299,6 +355,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -312,6 +369,7 @@ public function useHttpTransport(HttpTransport $transport): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -328,6 +386,7 @@ public function useHttpTransport(HttpTransport $transport): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -345,6 +404,7 @@ public function mapHttpTransport(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -364,6 +424,7 @@ public function mapHttpTransport(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -379,6 +440,7 @@ public function openSQLConnectionVia(\Closure $sql): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -395,6 +457,7 @@ public function openSQLConnectionVia(\Closure $sql): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -412,6 +475,7 @@ public function mapSQLConnection(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -431,6 +495,7 @@ public function mapSQLConnection(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -444,6 +509,7 @@ public function useServerControl(Control\Server $server): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -460,6 +526,7 @@ public function useServerControl(Control\Server $server): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -477,6 +544,7 @@ public function mapServerControl(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -496,6 +564,7 @@ public function mapServerControl(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -509,6 +578,7 @@ public function useServerStatus(Status\Server $server): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -525,6 +595,7 @@ public function useServerStatus(Status\Server $server): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -542,6 +613,7 @@ public function mapServerStatus(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -561,6 +633,7 @@ public function mapServerStatus(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -574,6 +647,7 @@ public function useFileWatch(Watch $watch): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -590,6 +664,7 @@ public function useFileWatch(Watch $watch): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -607,6 +682,7 @@ public function mapFileWatch(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -626,6 +702,7 @@ public function mapFileWatch(\Closure $map): self $this->filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -641,6 +718,7 @@ public function mountFilesystemVia(\Closure $filesystem): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -657,6 +735,7 @@ public function mountFilesystemVia(\Closure $filesystem): self $filesystem, $this->mapFilesystem, $this->signals, + $this->mapSignals, ); } @@ -674,6 +753,7 @@ public function mapFilesystem(\Closure $map): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -693,6 +773,7 @@ public function mapFilesystem(\Closure $map): self $config, ), $this->signals, + $this->mapSignals, ); } @@ -706,6 +787,7 @@ public function handleSignalsVia(Handler $handler): self $this->clock, $this->mapClock, $this->io, + $this->mapIO, $this->halt, $this->mapHalt, $this->path, @@ -722,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, + ), ); } @@ -765,7 +886,7 @@ public function filesystem(Path $path): Attempt #[\NoDiscard] public function io(): IO { - return $this->io; + return ($this->mapIO)($this->io, $this); } /** @@ -866,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); } }