diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 189105d..2f3eecb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,5 +12,3 @@ jobs: uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main cs: uses: innmind/github-workflows/.github/workflows/cs.yml@main - with: - php-version: '8.2' diff --git a/.github/workflows/extensive.yml b/.github/workflows/extensive.yml new file mode 100644 index 0000000..257f139 --- /dev/null +++ b/.github/workflows/extensive.yml @@ -0,0 +1,12 @@ +name: Extensive CI + +on: + push: + tags: + - '*' + paths: + - '.github/workflows/extensive.yml' + +jobs: + blackbox: + uses: innmind/github-workflows/.github/workflows/extensive.yml@main diff --git a/CHANGELOG.md b/CHANGELOG.md index fcfeefb..9d6b036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires PHP `8.4` +- `Innmind\Server\Status\Server` is now a final class, all previous implementations are now flagged as internal +- `Innmind\Server\Status\Server\Processes::all()` now returns an `Innmind\Immutable\Sequence` +- `Innmind\Server\Status\Server\Disk::volumes()` now returns an `Innmind\Immutable\Sequence` +- `Innmind\Server\Status\Server\Disk` is now a final class +- `Innmind\Server\Status\Server\Processes` is now a final class +- Requires `innmind/time:~1.0` + ## 5.0.0 - 2025-05-08 ### Changed diff --git a/blackbox.php b/blackbox.php index 50022e2..67a2468 100644 --- a/blackbox.php +++ b/blackbox.php @@ -10,6 +10,10 @@ }; Application::new($argv) + ->when( + \getenv('BLACKBOX_SET_SIZE') !== false, + static fn(Application $app) => $app->scenariiPerProof((int) \getenv('BLACKBOX_SET_SIZE')), + ) ->when( \getenv('ENABLE_COVERAGE') !== false, static fn(Application $app) => $app diff --git a/composer.json b/composer.json index 2f6b577..cd9c38f 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,13 @@ "issues": "http://github.com/Innmind/ServerStatus/issues" }, "require": { - "php": "~8.2", - "innmind/immutable": "~5.14", - "innmind/time-continuum": "^4.1.1", - "innmind/url": "~4.0", + "php": "~8.4", + "innmind/immutable": "~6.0", + "innmind/time": "~1.0", + "innmind/url": "~5.0", "psr/log": "~3.0", - "innmind/server-control": "~6.0", - "innmind/validation": "^2.0" + "innmind/server-control": "~7.0", + "innmind/validation": "~3.0" }, "autoload": { "psr-4": { @@ -34,7 +34,7 @@ }, "require-dev": { "innmind/black-box": "~6.1", - "innmind/static-analysis": "~1.2.1", + "innmind/static-analysis": "~1.3", "innmind/coding-standard": "~2.0" } } diff --git a/src/Facade/Cpu/LinuxFacade.php b/src/Facade/Cpu/LinuxFacade.php index 4c35e87..d5cd1c9 100644 --- a/src/Facade/Cpu/LinuxFacade.php +++ b/src/Facade/Cpu/LinuxFacade.php @@ -3,10 +3,10 @@ namespace Innmind\Server\Status\Facade\Cpu; -use Innmind\Server\Status\{ - Server\Cpu, - Server\Cpu\Percentage, - Server\Cpu\Cores, +use Innmind\Server\Status\Server\{ + Cpu, + Cpu\Percentage, + Cpu\Cores, }; use Innmind\Server\Control\Server\{ Processes, @@ -53,7 +53,7 @@ public function __invoke(): Attempt static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat), + ->fold(Concat::monoid), ) ->flatMap($this->parse(...)); } @@ -80,7 +80,7 @@ private function parse(Str $output): Attempt static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat) + ->fold(Concat::monoid) ->toString(), ) ->map(static fn($cores) => (int) $cores) diff --git a/src/Facade/Cpu/OSXFacade.php b/src/Facade/Cpu/OSXFacade.php index b6d92a0..bf30f99 100644 --- a/src/Facade/Cpu/OSXFacade.php +++ b/src/Facade/Cpu/OSXFacade.php @@ -3,10 +3,10 @@ namespace Innmind\Server\Status\Facade\Cpu; -use Innmind\Server\Status\{ - Server\Cpu, - Server\Cpu\Percentage, - Server\Cpu\Cores, +use Innmind\Server\Status\Server\{ + Cpu, + Cpu\Percentage, + Cpu\Cores, }; use Innmind\Server\Control\Server\{ Processes, @@ -54,7 +54,7 @@ public function __invoke(): Attempt static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat), + ->fold(Concat::monoid), ) ->flatMap($this->parse(...)); } @@ -88,7 +88,7 @@ private function parse(Str $output): Attempt static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat), + ->fold(Concat::monoid), ) ->map(static fn($output) => $output->trim()) ->map(static fn($output) => $output->capture('~^hw.ncpu: (?P\d+)$~')) diff --git a/src/Facade/Memory/LinuxFacade.php b/src/Facade/Memory/LinuxFacade.php index 942a8f4..fbf7755 100644 --- a/src/Facade/Memory/LinuxFacade.php +++ b/src/Facade/Memory/LinuxFacade.php @@ -3,9 +3,9 @@ namespace Innmind\Server\Status\Facade\Memory; -use Innmind\Server\Status\{ - Server\Memory, - Server\Memory\Bytes, +use Innmind\Server\Status\Server\{ + Memory, + Memory\Bytes, }; use Innmind\Server\Control\Server\{ Processes, @@ -56,7 +56,7 @@ public function __invoke(): Attempt static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat), + ->fold(Concat::monoid), ) ->flatMap($this->parse(...)); } diff --git a/src/Facade/Memory/OSXFacade.php b/src/Facade/Memory/OSXFacade.php index 32cb132..325e1d2 100644 --- a/src/Facade/Memory/OSXFacade.php +++ b/src/Facade/Memory/OSXFacade.php @@ -112,6 +112,6 @@ private function run(Command $command): Str ->toSequence() ->flatMap(static fn($success) => $success->output()) ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat); + ->fold(Concat::monoid); } } diff --git a/src/Server.php b/src/Server.php index 8357826..c204219 100644 --- a/src/Server.php +++ b/src/Server.php @@ -3,33 +3,89 @@ namespace Innmind\Server\Status; -use Innmind\Server\Status\Server\{ - Cpu, - Memory, - Processes, - LoadAverage, - Disk, +use Innmind\Server\Status\{ + Servers\Implementation, + Servers\OSX, + Servers\Linux, + Servers\Logger, + Server\Cpu, + Server\Memory, + Server\Processes, + Server\LoadAverage, + Server\Disk, }; +use Innmind\Server\Control\Server as Control; +use Innmind\Time\Clock; use Innmind\Url\Path; use Innmind\Immutable\Attempt; +use Psr\Log\LoggerInterface; -interface Server +final class Server { + private function __construct( + private Implementation $implementation, + ) { + } + + public static function osx( + Clock $clock, + Control $control, + EnvironmentPath $path, + ): self { + return new self(OSX::of($clock, $control, $path)); + } + + public static function linux( + Clock $clock, + Control $control, + ): self { + return new self(Linux::of($clock, $control)); + } + + public static function logger(self $server, LoggerInterface $logger): self + { + return new self(Logger::of( + $server->implementation, + $logger, + )); + } + /** * @return Attempt */ - public function cpu(): Attempt; + public function cpu(): Attempt + { + return $this->implementation->cpu(); + } /** * @return Attempt */ - public function memory(): Attempt; - public function processes(): Processes; + public function memory(): Attempt + { + return $this->implementation->memory(); + } + + public function processes(): Processes + { + return $this->implementation->processes(); + } /** * @return Attempt */ - public function loadAverage(): Attempt; - public function disk(): Disk; - public function tmp(): Path; + public function loadAverage(): Attempt + { + return $this->implementation->loadAverage(); + } + + public function disk(): Disk + { + return $this->implementation->disk(); + } + + public function tmp(): Path + { + return Path::of(\rtrim(\sys_get_temp_dir(), '/').'/'); + } } diff --git a/src/Server/Disk.php b/src/Server/Disk.php index eb6273b..3265fc9 100644 --- a/src/Server/Disk.php +++ b/src/Server/Disk.php @@ -4,23 +4,58 @@ namespace Innmind\Server\Status\Server; use Innmind\Server\Status\Server\Disk\{ + Implementation, + Unix, + Logger, Volume, Volume\MountPoint, }; +use Innmind\Server\Control\Server\Processes; use Innmind\Immutable\{ - Set, + Sequence, Maybe, }; +use Psr\Log\LoggerInterface; -interface Disk +final class Disk { + private function __construct( + private Implementation $implementation, + ) { + } + + /** + * @internal + */ + public static function of(Processes $processes): self + { + return new self(Unix::of($processes)); + } + + /** + * @internal + */ + public static function logger(self $disk, LoggerInterface $logger): self + { + return new self(Logger::of( + $disk->implementation, + $logger, + )); + } + /** - * @return Set + * @return Sequence */ - public function volumes(): Set; + public function volumes(): Sequence + { + return $this->implementation->volumes(); + } /** * @return Maybe */ - public function get(MountPoint $point): Maybe; + public function get(MountPoint $point): Maybe + { + return $this->implementation->get($point); + } } diff --git a/src/Server/Disk/Implementation.php b/src/Server/Disk/Implementation.php new file mode 100644 index 0000000..b7d7605 --- /dev/null +++ b/src/Server/Disk/Implementation.php @@ -0,0 +1,26 @@ + + */ + public function volumes(): Sequence; + + /** + * @return Maybe + */ + public function get(MountPoint $point): Maybe; +} diff --git a/src/Server/Disk/Logger.php b/src/Server/Disk/Logger.php index aafab47..90c676c 100644 --- a/src/Server/Disk/Logger.php +++ b/src/Server/Disk/Logger.php @@ -3,20 +3,20 @@ namespace Innmind\Server\Status\Server\Disk; -use Innmind\Server\Status\{ - Server\Disk, - Server\Disk\Volume\MountPoint, -}; +use Innmind\Server\Status\Server\Disk\Volume\MountPoint; use Innmind\Immutable\{ - Set, + Sequence, Maybe, }; use Psr\Log\LoggerInterface; -final class Logger implements Disk +/** + * @internal + */ +final class Logger implements Implementation { private function __construct( - private Disk $disk, + private Implementation $disk, private LoggerInterface $logger, ) { } @@ -24,13 +24,13 @@ private function __construct( /** * @internal */ - public static function of(Disk $disk, LoggerInterface $logger): self + public static function of(Implementation $disk, LoggerInterface $logger): self { return new self($disk, $logger); } #[\Override] - public function volumes(): Set + public function volumes(): Sequence { $volumes = $this->disk->volumes(); $this->logger->debug('{count} volumes currently mounted', [ diff --git a/src/Server/Disk/Unix.php b/src/Server/Disk/Unix.php index 158e00a..d46480d 100644 --- a/src/Server/Disk/Unix.php +++ b/src/Server/Disk/Unix.php @@ -3,11 +3,10 @@ namespace Innmind\Server\Status\Server\Disk; -use Innmind\Server\Status\{ - Server\Disk, - Server\Disk\Volume\MountPoint, - Server\Disk\Volume\Usage, - Server\Memory\Bytes, +use Innmind\Server\Status\Server\{ + Disk\Volume\MountPoint, + Disk\Volume\Usage, + Memory\Bytes, }; use Innmind\Server\Control\Server\{ Processes, @@ -17,13 +16,16 @@ use Innmind\Validation\Is; use Innmind\Immutable\{ Str, - Set, + Sequence, Maybe, Map, Monoid\Concat, }; -final class Unix implements Disk +/** + * @internal + */ +final class Unix implements Implementation { private static array $columns = [ 'Size' => 'size', @@ -48,7 +50,7 @@ public static function of(Processes $processes): self } #[\Override] - public function volumes(): Set + public function volumes(): Sequence { return $this ->processes @@ -63,11 +65,10 @@ public function volumes(): Set ->output() ->filter(static fn($chunk) => $chunk->type() === Output\Type::output) // discard errors such as "df: getattrlist failed" ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat), + ->fold(Concat::monoid), ) ->map($this->parse(...)) ->toSequence() - ->toSet() ->flatMap(static fn($volumes) => $volumes); } @@ -80,9 +81,9 @@ public function get(MountPoint $point): Maybe } /** - * @return Set + * @return Sequence */ - private function parse(Str $output): Set + private function parse(Str $output): Sequence { $lines = $output ->trim() @@ -126,8 +127,8 @@ private function parse(Str $output): Set ->map(Volume::of(...)); }); - return $volumes - ->flatMap(static fn($volume) => $volume->toSequence()) // discard unparsed volumes - ->toSet(); + return $volumes->flatMap( + static fn($volume) => $volume->toSequence(), // discard unparsed volumes + ); } } diff --git a/src/Server/Process.php b/src/Server/Process.php index 63c9671..38db37c 100644 --- a/src/Server/Process.php +++ b/src/Server/Process.php @@ -10,7 +10,7 @@ Process\Memory, Cpu\Percentage, }; -use Innmind\TimeContinuum\PointInTime; +use Innmind\Time\Point; use Innmind\Immutable\Maybe; /** @@ -19,7 +19,7 @@ final class Process { /** - * @param Maybe $start + * @param Maybe $start */ private function __construct( private Pid $pid, @@ -35,7 +35,7 @@ private function __construct( * @internal * @psalm-pure * - * @param Maybe $start + * @param Maybe $start */ public static function of( Pid $pid, @@ -69,7 +69,7 @@ public function memory(): Memory } /** - * @return Maybe + * @return Maybe */ public function start(): Maybe { diff --git a/src/Server/Processes.php b/src/Server/Processes.php index 966628b..b28bb74 100644 --- a/src/Server/Processes.php +++ b/src/Server/Processes.php @@ -3,21 +3,67 @@ namespace Innmind\Server\Status\Server; -use Innmind\Server\Status\Server\Process\Pid; +use Innmind\Server\Status\Server\{ + Processes\Implementation, + Processes\Unix, + Processes\Logger, + Process\Pid, +}; +use Innmind\Server\Control\Server as Control; +use Innmind\Time\Clock; use Innmind\Immutable\{ - Set, + Sequence, Maybe, }; +use Psr\Log\LoggerInterface; -interface Processes +final class Processes { + private function __construct( + private Implementation $implementation, + ) { + } + + /** + * @internal + */ + public static function osx(Clock $clock, Control\Processes $processes): self + { + return new self(Unix::osx($clock, $processes)); + } + + /** + * @internal + */ + public static function linux(Clock $clock, Control\Processes $processes): self + { + return new self(Unix::linux($clock, $processes)); + } + + /** + * @internal + */ + public static function logger(self $processes, LoggerInterface $logger): self + { + return new self(Logger::of( + $processes->implementation, + $logger, + )); + } + /** - * @return Set + * @return Sequence */ - public function all(): Set; + public function all(): Sequence + { + return $this->implementation->all(); + } /** * @return Maybe */ - public function get(Pid $pid): Maybe; + public function get(Pid $pid): Maybe + { + return $this->implementation->get($pid); + } } diff --git a/src/Server/Processes/Implementation.php b/src/Server/Processes/Implementation.php new file mode 100644 index 0000000..972000f --- /dev/null +++ b/src/Server/Processes/Implementation.php @@ -0,0 +1,29 @@ + + */ + public function all(): Sequence; + + /** + * @return Maybe + */ + public function get(Pid $pid): Maybe; +} diff --git a/src/Server/Processes/Logger.php b/src/Server/Processes/Logger.php index 7003528..07ddf38 100644 --- a/src/Server/Processes/Logger.php +++ b/src/Server/Processes/Logger.php @@ -3,22 +3,24 @@ namespace Innmind\Server\Status\Server\Processes; -use Innmind\Server\Status\{ - Server\Processes, - Server\Process, - Server\Process\Pid, +use Innmind\Server\Status\Server\{ + Process, + Process\Pid, }; -use Innmind\TimeContinuum\Format; +use Innmind\Time\Format; use Innmind\Immutable\{ - Set, + Sequence, Maybe, }; use Psr\Log\LoggerInterface; -final class Logger implements Processes +/** + * @internal + */ +final class Logger implements Implementation { private function __construct( - private Processes $processes, + private Implementation $processes, private LoggerInterface $logger, ) { } @@ -26,13 +28,13 @@ private function __construct( /** * @internal */ - public static function of(Processes $processes, LoggerInterface $logger): self + public static function of(Implementation $processes, LoggerInterface $logger): self { return new self($processes, $logger); } #[\Override] - public function all(): Set + public function all(): Sequence { $all = $this->processes->all(); $this->logger->debug('{count} processes currently running', [ diff --git a/src/Server/Processes/Unix.php b/src/Server/Processes/Unix.php index cb285dd..c7012a5 100644 --- a/src/Server/Processes/Unix.php +++ b/src/Server/Processes/Unix.php @@ -3,17 +3,16 @@ namespace Innmind\Server\Status\Server\Processes; -use Innmind\Server\Status\{ - Server\Processes, - Server\Process, - Server\Process\Pid, - Server\Process\User, - Server\Process\Command, - Server\Process\Memory, - Server\Cpu\Percentage, +use Innmind\Server\Status\Server\{ + Process, + Process\Pid, + Process\User, + Process\Command, + Process\Memory, + Cpu\Percentage, }; use Innmind\Server\Control\Server as Control; -use Innmind\TimeContinuum\{ +use Innmind\Time\{ Clock, Format, }; @@ -21,38 +20,56 @@ use Innmind\Immutable\{ Str, Sequence, - Set, Maybe, Monoid\Concat, }; -final class Unix implements Processes +/** + * @internal + */ +final class Unix implements Implementation { private function __construct( private Clock $clock, private Control\Processes $processes, + private string $format, ) { } /** * @internal */ - public static function of(Clock $clock, Control\Processes $processes): self + public static function osx(Clock $clock, Control\Processes $processes): self { - return new self($clock, $processes); + return new self( + $clock, + $processes, + 'lstart,user,pid,%cpu,%mem,command', + ); + } + + /** + * @internal + */ + public static function linux(Clock $clock, Control\Processes $processes): self + { + return new self( + $clock, + $processes, + 'lstart,user,pid,%cpu,%mem,cmd', + ); } #[\Override] - public function all(): Set + public function all(): Sequence { return $this ->run( Control\Command::foreground('ps') - ->withShortOption('eo', $this->format()), + ->withShortOption('eo', $this->format), ) ->map($this->parse(...)) ->toSequence() - ->toSet() ->flatMap(static fn($processes) => $processes); } @@ -62,12 +79,12 @@ public function get(Pid $pid): Maybe return $this ->run( Control\Command::foreground('ps') - ->withShortOption('o', $this->format()) + ->withShortOption('o', $this->format) ->withShortOption('p', $pid->toString()), ) ->otherwise(fn() => $this->run( Control\Command::foreground('ps') - ->withShortOption('o', $this->format()) + ->withShortOption('o', $this->format) ->withShortOption('q', $pid->toString()), )) ->map($this->parse(...)) @@ -90,14 +107,14 @@ private function run(Control\Command $command): Maybe static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat), + ->fold(Concat::monoid), ); } /** - * @return Set + * @return Sequence */ - private function parse(Str $output): Set + private function parse(Str $output): Sequence { $lines = $output ->trim() @@ -137,20 +154,15 @@ private function parse(Str $output): Set ->keep(Is::string()->nonEmpty()->asPredicate()) ->map(Command::of(...)); $start = Maybe::just( - $this->clock->at($start, Format::of('D M j H:i:s Y')), + $this->clock->at($start, Format::of('D M j H:i:s Y'))->maybe(), ); return Maybe::all($pid, $user, $percentage, $memory, $start, $command) ->map(Process::of(...)); }); - return $processes - ->flatMap(static fn($process) => $process->toSequence()) // discard process that failed to be parsed - ->toSet(); - } - - private function format(): string - { - return \PHP_OS === 'Linux' ? 'lstart,user,pid,%cpu,%mem,cmd' : 'lstart,user,pid,%cpu,%mem,command'; + return $processes->flatMap( + static fn($process) => $process->toSequence(), // discard process that failed to be parsed + ); } } diff --git a/src/ServerFactory.php b/src/ServerFactory.php index 0f5376e..eb64076 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -3,12 +3,8 @@ namespace Innmind\Server\Status; -use Innmind\Server\Status\Servers\{ - OSX, - Linux, -}; use Innmind\Server\Control\Server as Control; -use Innmind\TimeContinuum\Clock; +use Innmind\Time\Clock; final class ServerFactory { @@ -18,8 +14,8 @@ public static function build( EnvironmentPath $path, ): Server { return match (\PHP_OS) { - 'Darwin' => OSX::of($clock, $control, $path), - 'Linux' => Linux::of($clock, $control), + 'Darwin' => Server::osx($clock, $control, $path), + 'Linux' => Server::linux($clock, $control), default => throw new \LogicException('Unsupported operating system '.\PHP_OS), }; } diff --git a/src/Servers/Implementation.php b/src/Servers/Implementation.php new file mode 100644 index 0000000..5b567b3 --- /dev/null +++ b/src/Servers/Implementation.php @@ -0,0 +1,36 @@ + + */ + public function cpu(): Attempt; + + /** + * @return Attempt + */ + public function memory(): Attempt; + public function processes(): Processes; + + /** + * @return Attempt + */ + public function loadAverage(): Attempt; + public function disk(): Disk; +} diff --git a/src/Servers/Linux.php b/src/Servers/Linux.php index 30dc344..578c4c0 100644 --- a/src/Servers/Linux.php +++ b/src/Servers/Linux.php @@ -4,7 +4,6 @@ namespace Innmind\Server\Status\Servers; use Innmind\Server\Status\{ - Server, Server\Processes, Facade\Cpu\LinuxFacade as CpuFacade, Facade\Memory\LinuxFacade as MemoryFacade, @@ -12,25 +11,27 @@ Server\Disk, }; use Innmind\Server\Control\Server as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\Url\Path; +use Innmind\Time\Clock; use Innmind\Immutable\Attempt; -final class Linux implements Server +/** + * @internal + */ +final class Linux implements Implementation { private CpuFacade $cpu; private MemoryFacade $memory; - private Processes\Unix $processes; + private Processes $processes; private LoadAverageFacade $loadAverage; - private Disk\Unix $disk; + private Disk $disk; private function __construct(Clock $clock, Control $control) { $this->cpu = new CpuFacade($control->processes()); $this->memory = new MemoryFacade($control->processes()); - $this->processes = Processes\Unix::of($clock, $control->processes()); + $this->processes = Processes::linux($clock, $control->processes()); $this->loadAverage = new LoadAverageFacade; - $this->disk = Disk\Unix::of($control->processes()); + $this->disk = Disk::of($control->processes()); } /** @@ -70,10 +71,4 @@ public function disk(): Disk { return $this->disk; } - - #[\Override] - public function tmp(): Path - { - return Path::of(\rtrim(\sys_get_temp_dir(), '/').'/'); - } } diff --git a/src/Servers/Logger.php b/src/Servers/Logger.php index ade1eb8..e7d3c1d 100644 --- a/src/Servers/Logger.php +++ b/src/Servers/Logger.php @@ -3,24 +3,25 @@ namespace Innmind\Server\Status\Servers; -use Innmind\Server\Status\{ - Server, - Server\Processes, - Server\Disk, +use Innmind\Server\Status\Server\{ + Processes, + Disk, }; -use Innmind\Url\Path; use Innmind\Immutable\Attempt; use Psr\Log\LoggerInterface; -final class Logger implements Server +/** + * @internal + */ +final class Logger implements Implementation { private function __construct( - private Server $server, + private Implementation $server, private LoggerInterface $logger, ) { } - public static function of(Server $server, LoggerInterface $logger): self + public static function of(Implementation $server, LoggerInterface $logger): self { return new self($server, $logger); } @@ -60,7 +61,7 @@ public function memory(): Attempt #[\Override] public function processes(): Processes { - return Processes\Logger::of( + return Processes::logger( $this->server->processes(), $this->logger, ); @@ -83,20 +84,9 @@ public function loadAverage(): Attempt #[\Override] public function disk(): Disk { - return Disk\Logger::of( + return Disk::logger( $this->server->disk(), $this->logger, ); } - - #[\Override] - public function tmp(): Path - { - $tmp = $this->server->tmp(); - $this->logger->debug('Temporary folder located at: {path}', [ - 'path' => $tmp->toString(), - ]); - - return $tmp; - } } diff --git a/src/Servers/OSX.php b/src/Servers/OSX.php index aecf206..26101eb 100644 --- a/src/Servers/OSX.php +++ b/src/Servers/OSX.php @@ -4,7 +4,6 @@ namespace Innmind\Server\Status\Servers; use Innmind\Server\Status\{ - Server, Server\Processes, Facade\Cpu\OSXFacade as CpuFacade, Facade\Memory\OSXFacade as MemoryFacade, @@ -13,25 +12,27 @@ EnvironmentPath, }; use Innmind\Server\Control\Server as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\Url\Path; +use Innmind\Time\Clock; use Innmind\Immutable\Attempt; -final class OSX implements Server +/** + * @internal + */ +final class OSX implements Implementation { private CpuFacade $cpu; private MemoryFacade $memory; - private Processes\Unix $processes; + private Processes $processes; private LoadAverageFacade $loadAverage; - private Disk\Unix $disk; + private Disk $disk; private function __construct(Clock $clock, Control $control, EnvironmentPath $path) { $this->cpu = new CpuFacade($control->processes()); $this->memory = new MemoryFacade($control->processes(), $path); - $this->processes = Processes\Unix::of($clock, $control->processes()); + $this->processes = Processes::osx($clock, $control->processes()); $this->loadAverage = new LoadAverageFacade; - $this->disk = Disk\Unix::of($control->processes()); + $this->disk = Disk::of($control->processes()); } /** @@ -71,10 +72,4 @@ public function disk(): Disk { return $this->disk; } - - #[\Override] - public function tmp(): Path - { - return Path::of(\rtrim(\sys_get_temp_dir(), '/').'/'); - } } diff --git a/tests/Facade/Cpu/LinuxFacadeTest.php b/tests/Facade/Cpu/LinuxFacadeTest.php index 5a6c26a..add24ea 100644 --- a/tests/Facade/Cpu/LinuxFacadeTest.php +++ b/tests/Facade/Cpu/LinuxFacadeTest.php @@ -8,8 +8,10 @@ Server\Cpu, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -22,7 +24,7 @@ public function setUp(): void $this->server = Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ); } diff --git a/tests/Facade/Cpu/OSXFacadeTest.php b/tests/Facade/Cpu/OSXFacadeTest.php index bd5ec6f..a7bb164 100644 --- a/tests/Facade/Cpu/OSXFacadeTest.php +++ b/tests/Facade/Cpu/OSXFacadeTest.php @@ -8,8 +8,10 @@ Server\Cpu, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -22,7 +24,7 @@ public function setUp(): void $this->server = Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ); } diff --git a/tests/Facade/Memory/LinuxFacadeTest.php b/tests/Facade/Memory/LinuxFacadeTest.php index deefca5..b40812d 100644 --- a/tests/Facade/Memory/LinuxFacadeTest.php +++ b/tests/Facade/Memory/LinuxFacadeTest.php @@ -8,8 +8,10 @@ Server\Memory, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -22,7 +24,7 @@ public function setUp(): void $this->server = Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ); } diff --git a/tests/Facade/Memory/OSXFacadeTest.php b/tests/Facade/Memory/OSXFacadeTest.php index 3ecc610..bd82925 100644 --- a/tests/Facade/Memory/OSXFacadeTest.php +++ b/tests/Facade/Memory/OSXFacadeTest.php @@ -9,8 +9,10 @@ EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -23,7 +25,7 @@ public function setUp(): void $this->server = Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ); } diff --git a/tests/Server/Disk/LoggerDiskTest.php b/tests/Server/Disk/LoggerDiskTest.php index 77d43dd..6b85fcc 100644 --- a/tests/Server/Disk/LoggerDiskTest.php +++ b/tests/Server/Disk/LoggerDiskTest.php @@ -4,7 +4,7 @@ namespace Tests\Innmind\Server\Status\Server\Disk; use Innmind\Server\Status\{ - Server\Disk\Logger, + Server, Server\Disk, Server\Disk\Volume, Server\Disk\Volume\MountPoint, @@ -12,10 +12,12 @@ EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; -use Innmind\Immutable\Set; +use Innmind\Immutable\Sequence; use Psr\Log\NullLogger; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -23,22 +25,22 @@ class LoggerDiskTest extends TestCase { public function testInterface() { - $this->assertInstanceOf(Disk::class, Logger::of( - $this->disk(), + $this->assertInstanceOf(Disk::class, Server::logger( + $this->server(), new NullLogger, - )); + )->disk()); } public function testVolumes() { - $disk = Logger::of($this->disk(), new NullLogger); + $disk = Server::logger($this->server(), new NullLogger)->disk(); - $this->assertInstanceOf(Set::class, $disk->volumes()); + $this->assertInstanceOf(Sequence::class, $disk->volumes()); } public function testGet() { - $disk = Logger::of($this->disk(), new NullLogger); + $disk = Server::logger($this->server(), new NullLogger)->disk(); $this->assertInstanceOf(Volume::class, $disk->get(MountPoint::of('/'))->match( static fn($volume) => $volume, @@ -46,16 +48,16 @@ public function testGet() )); } - private function disk(): Disk + private function server(): Server { return ServerFactory::build( Clock::live(), Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ), EnvironmentPath::of(\getenv('PATH')), - )->disk(); + ); } } diff --git a/tests/Server/Disk/UnixDiskTest.php b/tests/Server/Disk/UnixDiskTest.php index d381420..c5a319a 100644 --- a/tests/Server/Disk/UnixDiskTest.php +++ b/tests/Server/Disk/UnixDiskTest.php @@ -4,16 +4,19 @@ namespace Tests\Innmind\Server\Status\Server\Disk; use Innmind\Server\Status\{ - Server\Disk\Unix, + ServerFactory, Server\Disk, Server\Disk\Volume, Server\Disk\Volume\MountPoint, + EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; -use Innmind\Immutable\Set; +use Innmind\Immutable\Sequence; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class UnixDiskTest extends TestCase @@ -22,13 +25,15 @@ class UnixDiskTest extends TestCase public function setUp(): void { - $this->disk = Unix::of( + $this->disk = ServerFactory::build( + Clock::live(), Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), - )->processes(), - ); + Halt::new(), + ), + EnvironmentPath::of(\getenv('PATH')), + )->disk(); } public function testInterface() @@ -40,7 +45,7 @@ public function testVolumes() { $volumes = $this->disk->volumes(); - $this->assertInstanceOf(Set::class, $volumes); + $this->assertInstanceOf(Sequence::class, $volumes); $this->assertGreaterThanOrEqual(1, $volumes->size()); $this->assertTrue( $volumes diff --git a/tests/Server/ProcessTest.php b/tests/Server/ProcessTest.php index 3da229c..6295f0e 100644 --- a/tests/Server/ProcessTest.php +++ b/tests/Server/ProcessTest.php @@ -12,7 +12,7 @@ Cpu\Percentage, }; use Innmind\Immutable\Maybe; -use Fixtures\Innmind\TimeContinuum\PointInTime; +use Fixtures\Innmind\Time\Point; use Innmind\BlackBox\{ PHPUnit\BlackBox, PHPUnit\Framework\TestCase, @@ -25,7 +25,7 @@ class ProcessTest extends TestCase public function testInterface() { $this - ->forAll(PointInTime::any()) + ->forAll(Point::any()) ->then(function($pointInTime) { $process = Process::of( $pid = Pid::of(1), diff --git a/tests/Server/Processes/LoggerProcessesTest.php b/tests/Server/Processes/LoggerProcessesTest.php index 2e4b38c..2b05bbd 100644 --- a/tests/Server/Processes/LoggerProcessesTest.php +++ b/tests/Server/Processes/LoggerProcessesTest.php @@ -4,7 +4,7 @@ namespace Tests\Innmind\Server\Status\Server\Processes; use Innmind\Server\Status\{ - Server\Processes\Logger, + Server, Server\Processes, Server\Process, Server\Process\Pid, @@ -12,10 +12,12 @@ EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; -use Innmind\Immutable\Set; +use Innmind\Immutable\Sequence; use Psr\Log\NullLogger; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -23,22 +25,22 @@ class LoggerProcessesTest extends TestCase { public function testInterface() { - $this->assertInstanceOf(Processes::class, Logger::of( - $this->processes(), + $this->assertInstanceOf(Processes::class, Server::logger( + $this->server(), new NullLogger, - )); + )->processes()); } public function testAll() { - $processes = Logger::of($this->processes(), new NullLogger); + $processes = Server::logger($this->server(), new NullLogger)->processes(); - $this->assertInstanceOf(Set::class, $processes->all()); + $this->assertInstanceOf(Sequence::class, $processes->all()); } public function testGet() { - $processes = Logger::of($this->processes(), new NullLogger); + $processes = Server::logger($this->server(), new NullLogger)->processes(); $this->assertInstanceOf(Process::class, $processes->get(Pid::of(1))->match( static fn($process) => $process, @@ -46,16 +48,16 @@ public function testGet() )); } - private function processes(): Processes + private function server(): Server { return ServerFactory::build( Clock::live(), Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ), EnvironmentPath::of(\getenv('PATH')), - )->processes(); + ); } } diff --git a/tests/Server/Processes/UnixProcessesTest.php b/tests/Server/Processes/UnixProcessesTest.php index f30eab6..1a5299d 100644 --- a/tests/Server/Processes/UnixProcessesTest.php +++ b/tests/Server/Processes/UnixProcessesTest.php @@ -4,19 +4,20 @@ namespace Tests\Innmind\Server\Status\Server\Processes; use Innmind\Server\Status\{ - Server\Processes\Unix, + ServerFactory, Server\Processes, Server\Process, Server\Process\Pid, + EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\{ +use Innmind\Time\{ Clock, - PointInTime, + Point, + Halt, }; -use Innmind\TimeWarp\Halt\Usleep; use Innmind\IO\IO; -use Innmind\Immutable\Set; +use Innmind\Immutable\Sequence; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class UnixProcessesTest extends TestCase @@ -25,14 +26,15 @@ class UnixProcessesTest extends TestCase public function setUp(): void { - $this->processes = Unix::of( + $this->processes = ServerFactory::build( Clock::live(), Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), - )->processes(), - ); + Halt::new(), + ), + EnvironmentPath::of(\getenv('PATH')), + )->processes(); } public function testInterface() @@ -44,7 +46,7 @@ public function testAll() { $all = $this->processes->all(); - $this->assertInstanceOf(Set::class, $all); + $this->assertInstanceOf(Sequence::class, $all); $this->assertGreaterThanOrEqual(1, $all->size()); $this->assertSame( 'root', @@ -111,7 +113,7 @@ public function testProcessTimeIsStillAccessible() ); $this->assertInstanceOf(Process::class, $process); - $this->assertInstanceOf(PointInTime::class, $process->start()->match( + $this->assertInstanceOf(Point::class, $process->start()->match( static fn($start) => $start, static fn() => null, )); diff --git a/tests/ServerFactoryTest.php b/tests/ServerFactoryTest.php index 7ce4be5..0fa1dc5 100644 --- a/tests/ServerFactoryTest.php +++ b/tests/ServerFactoryTest.php @@ -9,8 +9,10 @@ EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -23,7 +25,7 @@ public function testMake() Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ), EnvironmentPath::of(\getenv('PATH')), )); diff --git a/tests/Servers/LinuxTest.php b/tests/Servers/LinuxTest.php index 3b98e54..f945367 100644 --- a/tests/Servers/LinuxTest.php +++ b/tests/Servers/LinuxTest.php @@ -4,7 +4,6 @@ namespace Tests\Innmind\Server\Status\Servers; use Innmind\Server\Status\{ - Servers\Linux, Server, Server\Cpu, Server\Memory, @@ -13,8 +12,10 @@ Server\Disk }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\Url\Path; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -25,12 +26,12 @@ class LinuxTest extends TestCase public function setUp(): void { - $this->server = Linux::of( + $this->server = Server::linux( Clock::live(), Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ), ); } diff --git a/tests/Servers/LoggerTest.php b/tests/Servers/LoggerTest.php index abbf52e..f336975 100644 --- a/tests/Servers/LoggerTest.php +++ b/tests/Servers/LoggerTest.php @@ -4,7 +4,6 @@ namespace Tests\Innmind\Server\Status\Servers; use Innmind\Server\Status\{ - Servers\Logger, Server, Server\Cpu, Server\Memory, @@ -15,8 +14,10 @@ EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\Url\Path; use Psr\Log\NullLogger; @@ -26,7 +27,7 @@ class LoggerTest extends TestCase { public function testInterface() { - $this->assertInstanceOf(Server::class, Logger::of( + $this->assertInstanceOf(Server::class, Server::logger( $this->server(), new NullLogger, )); @@ -34,7 +35,7 @@ public function testInterface() public function testCpu() { - $server = Logger::of($this->server(), new NullLogger); + $server = Server::logger($this->server(), new NullLogger); $this->assertInstanceOf(Cpu::class, $server->cpu()->match( static fn($cpu) => $cpu, @@ -44,7 +45,7 @@ public function testCpu() public function testMemory() { - $server = Logger::of($this->server(), new NullLogger); + $server = Server::logger($this->server(), new NullLogger); $this->assertInstanceOf(Memory::class, $server->memory()->match( static fn($memory) => $memory, @@ -54,34 +55,34 @@ public function testMemory() public function testProcesses() { - $server = Logger::of( + $server = Server::logger( $this->server(), new NullLogger, ); - $this->assertInstanceOf(Processes\Logger::class, $server->processes()); + $this->assertInstanceOf(Processes::class, $server->processes()); } public function testLoadAverage() { - $server = Logger::of($this->server(), new NullLogger); + $server = Server::logger($this->server(), new NullLogger); $this->assertInstanceOf(LoadAverage::class, $server->loadAverage()->unwrap()); } public function testDisk() { - $server = Logger::of( + $server = Server::logger( $this->server(), new NullLogger, ); - $this->assertInstanceOf(Disk\Logger::class, $server->disk()); + $this->assertInstanceOf(Disk::class, $server->disk()); } public function testTmp() { - $server = Logger::of($this->server(), new NullLogger); + $server = Server::logger($this->server(), new NullLogger); $this->assertInstanceOf(Path::class, $server->tmp()); } @@ -93,7 +94,7 @@ private function server(): Server Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ), EnvironmentPath::of(\getenv('PATH')), ); diff --git a/tests/Servers/OSXTest.php b/tests/Servers/OSXTest.php index 7c71fbd..ba9a6b0 100644 --- a/tests/Servers/OSXTest.php +++ b/tests/Servers/OSXTest.php @@ -4,7 +4,6 @@ namespace Tests\Innmind\Server\Status\Servers; use Innmind\Server\Status\{ - Servers\OSX, Server, Server\Cpu, Server\Memory, @@ -14,8 +13,10 @@ EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; -use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\Time\{ + Clock, + Halt, +}; use Innmind\IO\IO; use Innmind\Url\Path; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ class OSXTest extends TestCase public function setUp(): void { - $this->server = OSX::of( + $this->server = Server::osx( Clock::live(), Control::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), ), EnvironmentPath::of(\getenv('PATH')), );