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/CHANGELOG.md b/CHANGELOG.md index d882e56..943e601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires PHP `8.4` +- Requires `innmind/server-control:~7.0` + ## 5.0.0 - 2025-05-08 ### Changed diff --git a/README.md b/README.md index e8fbab6..2b1ea0e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # FileWatch -[![Build Status](https://github.com/innmind/filewatch/workflows/CI/badge.svg?branch=master)](https://github.com/innmind/filewatch/actions?query=workflow%3ACI) +[![CI](https://github.com/Innmind/FileWatch/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Innmind/FileWatch/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/innmind/filewatch/branch/develop/graph/badge.svg)](https://codecov.io/gh/innmind/filewatch) [![Type Coverage](https://shepherd.dev/github/innmind/filewatch/coverage.svg)](https://shepherd.dev/github/innmind/filewatch) @@ -15,12 +15,9 @@ composer require innmind/file-watch ## Usage ```php -use Innmind\FileWatch\{ - Factory, - Stop, -}; +use Innmind\FileWatch\Factory; use Innmind\Server\Control\ServerFactory; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\TimeWarp\Halt; use Innmind\TimeContinuum\Clock; use Innmind\IO\IO; use Innmind\Url\Path; @@ -30,9 +27,9 @@ $watch = Factory::build( ServerFactory::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), + Halt::new(), )->processes(), - Usleep::new(), + Halt::new(), ); $count = $watch(Path::of('/to/some/file/or/folder'))(0, function(int $count, Continuation $continuation): Continuation { diff --git a/composer.json b/composer.json index 80aa487..7368bda 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ "issues": "http://github.com/Innmind/FileWatch/issues" }, "require": { - "php": "~8.2", - "innmind/url": "~4.0", - "innmind/server-control": "~6.0", - "innmind/time-warp": "~4.0", - "innmind/time-continuum": "^4.1.1", + "php": "~8.4", + "innmind/url": "~5.0", + "innmind/server-control": "~7.0", + "innmind/time-warp": "~5.1", + "innmind/time-continuum": "~5.1", "psr/log": "~3.0" }, "autoload": { @@ -33,7 +33,7 @@ } }, "require-dev": { - "innmind/static-analysis": "^1.2.1", + "innmind/static-analysis": "~1.3", "innmind/coding-standard": "~2.0", "innmind/black-box": "~6.1" } diff --git a/src/Ping/OutputDiff.php b/src/Ping/OutputDiff.php index e41b680..1fd6c77 100644 --- a/src/Ping/OutputDiff.php +++ b/src/Ping/OutputDiff.php @@ -49,7 +49,7 @@ public function __invoke(mixed $carry, callable $ping): Attempt $result = Sequence::lazy(function() { while (true) { yield $this->output(); - ($this->halt)($this->period); + $_ = ($this->halt)($this->period)->memoize(); } }) ->flatMap(static fn($maybe) => $maybe->match( @@ -136,11 +136,11 @@ private function diff(Sequence $previous, Sequence $now): bool { $previous = $previous ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat) + ->fold(Concat::monoid) ->toString(); $now = $now ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat) + ->fold(Concat::monoid) ->toString(); return $previous !== $now; diff --git a/src/Watch.php b/src/Watch.php index 21b8272..cb0176d 100644 --- a/src/Watch.php +++ b/src/Watch.php @@ -4,6 +4,7 @@ namespace Innmind\FileWatch; use Innmind\FileWatch\Watch\{ + Implementation, Kind, Logger, Fallback, @@ -19,7 +20,7 @@ final class Watch { private function __construct( - private Kind|Logger $implementation, + private Implementation $implementation, ) { } diff --git a/src/Watch/Implementation.php b/src/Watch/Implementation.php new file mode 100644 index 0000000..57a049d --- /dev/null +++ b/src/Watch/Implementation.php @@ -0,0 +1,15 @@ +directory()) { diff --git a/src/Watch/Logger.php b/src/Watch/Logger.php index 5a6e677..df9d4a1 100644 --- a/src/Watch/Logger.php +++ b/src/Watch/Logger.php @@ -10,14 +10,15 @@ /** * @internal */ -final class Logger +final class Logger implements Implementation { private function __construct( - private Kind $watch, + private Implementation $watch, private LoggerInterface $logger, ) { } + #[\Override] public function __invoke(Path $path): Ping\Implementation { return Ping\Logger::psr( @@ -27,17 +28,8 @@ public function __invoke(Path $path): Ping\Implementation ); } - public static function psr(Kind|self $watch, LoggerInterface $logger): self + public static function psr(Implementation $watch, LoggerInterface $logger): self { - return new self(self::extract($watch), $logger); - } - - private static function extract(Kind|self $watch): Kind - { - if ($watch instanceof Kind) { - return $watch; - } - - return self::extract($watch->watch); + return new self($watch, $logger); } } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index fb74172..f990150 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -7,12 +7,12 @@ Factory, Watch, }; -use Innmind\Server\Control\Server\{ - Processes\Unix, - Command, +use Innmind\Server\Control\{ + ServerFactory, + Server\Command, }; use Innmind\TimeContinuum\Clock; -use Innmind\TimeWarp\Halt\Usleep; +use Innmind\TimeWarp\Halt; use Innmind\IO\IO; use Innmind\Url\Path; use Psr\Log\NullLogger; @@ -34,16 +34,16 @@ public function tearDown(): void public function testWatchFile() { \touch('/tmp/innmind/watch-file'); - $processes = Unix::of( + $processes = ServerFactory::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), - ); + Halt::new(), + )->processes(); $process = $processes->execute(Command::background( 'sleep 1 && echo foo >> /tmp/innmind/watch-file && sleep 1 && echo foo >> /tmp/innmind/watch-file && sleep 1 && echo foo >> /tmp/innmind/watch-file', )); - $watch = Factory::build($processes, Usleep::new()); + $watch = Factory::build($processes, Halt::new()); $either = $watch(Path::of('/tmp/innmind/watch-file'))(0, static function($count, $continuation) { ++$count; @@ -66,16 +66,16 @@ public function testWatchFile() public function testWatchDirectory() { - $processes = Unix::of( + $processes = ServerFactory::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), - ); + Halt::new(), + )->processes(); $process = $processes->execute(Command::background( 'sleep 1 && touch /tmp/innmind/watch-file && sleep 1 && rm /tmp/innmind/watch-file', )); - $watch = Factory::build($processes, Usleep::new()); + $watch = Factory::build($processes, Halt::new()); $either = $watch(Path::of('/tmp/innmind/'))(0, static function($count, $continuation) { ++$count; @@ -98,13 +98,13 @@ public function testWatchDirectory() public function testReturnErrorWhenWatchingUnknownFile() { - $processes = Unix::of( + $processes = ServerFactory::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), - ); + Halt::new(), + )->processes(); - $watch = Factory::build($processes, Usleep::new()); + $watch = Factory::build($processes, Halt::new()); $either = $watch(Path::of('/unknown/'))(null, static fn($_, $continuation) => $continuation); @@ -118,16 +118,16 @@ public function testReturnErrorWhenWatchingUnknownFile() public function testLog() { \touch('/tmp/innmind/watch-file'); - $processes = Unix::of( + $processes = ServerFactory::build( Clock::live(), IO::fromAmbientAuthority(), - Usleep::new(), - ); + Halt::new(), + )->processes(); $process = $processes->execute(Command::background( 'sleep 1 && echo foo >> /tmp/innmind/watch-file && sleep 1 && echo foo >> /tmp/innmind/watch-file && sleep 1 && echo foo >> /tmp/innmind/watch-file', - )); + ))->unwrap(); - $inner = Factory::build($processes, Usleep::new()); + $inner = Factory::build($processes, Halt::new()); $watch = Watch::logger($inner, new NullLogger); $either = $watch(Path::of('/tmp/innmind/watch-file'))(0, static function($count, $continuation) {