From 930b2e112ebfe92afad6bca0ad00f5015b1c2fbe Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 30 Jul 2025 18:27:07 +0200 Subject: [PATCH] update dependencies --- CHANGELOG.md | 4 ++ composer.json | 9 +--- src/LineParser/Apache/TimeFormat.php | 18 -------- src/LineParser/ApacheAccess.php | 5 ++- src/LineParser/Monolog.php | 9 +++- tests/LineParser/ApacheAccessTest.php | 65 ++++++++++++++------------- tests/LineParser/MonologTest.php | 21 +++++---- tests/LogTest.php | 8 ++-- tests/ReaderTest.php | 24 +++++----- 9 files changed, 80 insertions(+), 83 deletions(-) delete mode 100644 src/LineParser/Apache/TimeFormat.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dcaa57..f8f66b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Changed + +- Requires `innmind/foundation:~1.3` + ### Fixed - PHP `8.4` deprecations diff --git a/composer.json b/composer.json index 2618339..8ec6496 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,8 @@ }, "require": { "php": "~8.2", - "innmind/immutable": "~4.9|~5.0", - "innmind/time-continuum": "~3.1", - "psr/log": "^3.0", - "innmind/url": "~4.1", - "innmind/http": "~7.0", - "innmind/filesystem": "~7.0", - "innmind/json": "^1.1" + "innmind/foundation": "~1.3", + "psr/log": "^3.0" }, "autoload": { "psr-4": { diff --git a/src/LineParser/Apache/TimeFormat.php b/src/LineParser/Apache/TimeFormat.php deleted file mode 100644 index 7bb9eca..0000000 --- a/src/LineParser/Apache/TimeFormat.php +++ /dev/null @@ -1,18 +0,0 @@ -get('time') ->map(static fn($time) => $time->toString()) - ->flatMap(fn($time) => $this->clock->at($time, new Apache\TimeFormat)); + ->keep(Is::string()->nonEmpty()->asPredicate()) + ->flatMap($this->clock->ofFormat(Format::of('d/M/Y:H:i:s O'))->at(...)); $user = $parts ->get('user') ->map(static fn($user) => Attribute::of('user', $user)); diff --git a/src/LineParser/Monolog.php b/src/LineParser/Monolog.php index 3ccd444..68b0ba1 100644 --- a/src/LineParser/Monolog.php +++ b/src/LineParser/Monolog.php @@ -11,7 +11,11 @@ Log\Attribute\Monolog\Level, Log\Attribute\Monolog\Message, }; -use Innmind\TimeContinuum\Clock; +use Innmind\TimeContinuum\{ + Clock, + Format, +}; +use Innmind\Validation\Is; use Innmind\Json\{ Json, Exception\Exception, @@ -96,7 +100,8 @@ public function __invoke(Str $line): Maybe $time = $parts ->get('time') ->map(static fn($time) => $time->toString()) - ->flatMap($this->clock->at(...)); + ->keep(Is::string()->nonEmpty()->asPredicate()) + ->flatMap($this->clock->ofFormat(Format::of('Y-m-d H:i:s'))->at(...)); return $time->flatMap( static fn($time) => $attributes->map( diff --git a/tests/LineParser/ApacheAccessTest.php b/tests/LineParser/ApacheAccessTest.php index e28bafb..5667eef 100644 --- a/tests/LineParser/ApacheAccessTest.php +++ b/tests/LineParser/ApacheAccessTest.php @@ -8,10 +8,9 @@ LineParser, Log, }; -use Innmind\TimeContinuum\Earth\{ +use Innmind\TimeContinuum\{ Clock, - Timezone\UTC, - Format\ISO8601, + Format, }; use Innmind\Http\{ Method, @@ -30,13 +29,15 @@ class ApacheAccessTest extends TestCase { public function testInterface() { - $this->assertInstanceOf(LineParser::class, ApacheAccess::of(new Clock)); + $this->assertInstanceOf(LineParser::class, ApacheAccess::of(Clock::live())); } #[DataProvider('lines')] public function testInvokation($line, $client, $user, $time, $method, $path, $protocol, $code, $size) { - $parse = ApacheAccess::of(new Clock(new UTC(-8))); + $parse = ApacheAccess::of( + Clock::live()->switch(static fn($timezones) => $timezones->utc()), + ); $log = $parse(Str::of($line))->match( static fn($log) => $log, @@ -44,7 +45,7 @@ public function testInvokation($line, $client, $user, $time, $method, $path, $pr ); $this->assertInstanceOf(Log::class, $log); - $this->assertSame($time, $log->time()->format(new ISO8601)); + $this->assertSame($time, $log->time()->format(Format::iso8601())); $this->assertInstanceOf( Host::class, $log @@ -162,7 +163,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:05:49 -0800] "GET /twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12846', '64.242.88.10', '-', - '2004-03-07T16:05:49-08:00', + '2004-03-08T00:05:49+00:00', 'GET', '/twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables', '1.1', @@ -173,7 +174,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:06:51 -0800] "GET /twiki/bin/rdiff/TWiki/NewUserTemplate?rev1=1.3&rev2=1.2 HTTP/1.1" 200 4523', '64.242.88.10', '-', - '2004-03-07T16:06:51-08:00', + '2004-03-08T00:06:51+00:00', 'GET', '/twiki/bin/rdiff/TWiki/NewUserTemplate?rev1=1.3&rev2=1.2', '1.1', @@ -184,7 +185,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:10:02 -0800] "GET /mailman/listinfo/hsdivision HTTP/1.1" 200 6291', '64.242.88.10', '-', - '2004-03-07T16:10:02-08:00', + '2004-03-08T00:10:02+00:00', 'GET', '/mailman/listinfo/hsdivision', '1.1', @@ -195,7 +196,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:11:58 -0800] "GET /twiki/bin/view/TWiki/WikiSyntax HTTP/1.1" 200 7352', '64.242.88.10', '-', - '2004-03-07T16:11:58-08:00', + '2004-03-08T00:11:58+00:00', 'GET', '/twiki/bin/view/TWiki/WikiSyntax', '1.1', @@ -206,7 +207,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:20:55 -0800] "GET /twiki/bin/view/Main/DCCAndPostFix HTTP/1.1" 200 5253', '64.242.88.10', '-', - '2004-03-07T16:20:55-08:00', + '2004-03-08T00:20:55+00:00', 'GET', '/twiki/bin/view/Main/DCCAndPostFix', '1.1', @@ -217,7 +218,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:23:12 -0800] "GET /twiki/bin/oops/TWiki/AppendixFileSystem?template=oopsmore¶m1=1.12¶m2=1.12 HTTP/1.1" 200 11382', '64.242.88.10', '-', - '2004-03-07T16:23:12-08:00', + '2004-03-08T00:23:12+00:00', 'GET', '/twiki/bin/oops/TWiki/AppendixFileSystem?template=oopsmore¶m1=1.12¶m2=1.12', '1.1', @@ -228,7 +229,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:24:16 -0800] "GET /twiki/bin/view/Main/PeterThoeny HTTP/1.1" 200 4924', '64.242.88.10', '-', - '2004-03-07T16:24:16-08:00', + '2004-03-08T00:24:16+00:00', 'GET', '/twiki/bin/view/Main/PeterThoeny', '1.1', @@ -239,7 +240,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:29:16 -0800] "GET /twiki/bin/edit/Main/Header_checks?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12851', '64.242.88.10', '-', - '2004-03-07T16:29:16-08:00', + '2004-03-08T00:29:16+00:00', 'GET', '/twiki/bin/edit/Main/Header_checks?topicparent=Main.ConfigurationVariables', '1.1', @@ -250,7 +251,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:30:29 -0800] "GET /twiki/bin/attach/Main/OfficeLocations HTTP/1.1" 401 12851', '64.242.88.10', '-', - '2004-03-07T16:30:29-08:00', + '2004-03-08T00:30:29+00:00', 'GET', '/twiki/bin/attach/Main/OfficeLocations', '1.1', @@ -261,7 +262,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:31:48 -0800] "GET /twiki/bin/view/TWiki/WebTopicEditTemplate HTTP/1.1" 200 3732', '64.242.88.10', '-', - '2004-03-07T16:31:48-08:00', + '2004-03-08T00:31:48+00:00', 'GET', '/twiki/bin/view/TWiki/WebTopicEditTemplate', '1.1', @@ -272,7 +273,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:32:50 -0800] "GET /twiki/bin/view/Main/WebChanges HTTP/1.1" 200 40520', '64.242.88.10', '-', - '2004-03-07T16:32:50-08:00', + '2004-03-08T00:32:50+00:00', 'GET', '/twiki/bin/view/Main/WebChanges', '1.1', @@ -283,7 +284,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:33:53 -0800] "GET /twiki/bin/edit/Main/Smtpd_etrn_restrictions?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12851', '64.242.88.10', '-', - '2004-03-07T16:33:53-08:00', + '2004-03-08T00:33:53+00:00', 'GET', '/twiki/bin/edit/Main/Smtpd_etrn_restrictions?topicparent=Main.ConfigurationVariables', '1.1', @@ -294,7 +295,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:35:19 -0800] "GET /mailman/listinfo/business HTTP/1.1" 200 6379', '64.242.88.10', '-', - '2004-03-07T16:35:19-08:00', + '2004-03-08T00:35:19+00:00', 'GET', '/mailman/listinfo/business', '1.1', @@ -305,7 +306,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:36:22 -0800] "GET /twiki/bin/rdiff/Main/WebIndex?rev1=1.2&rev2=1.1 HTTP/1.1" 200 46373', '64.242.88.10', '-', - '2004-03-07T16:36:22-08:00', + '2004-03-08T00:36:22+00:00', 'GET', '/twiki/bin/rdiff/Main/WebIndex?rev1=1.2&rev2=1.1', '1.1', @@ -316,7 +317,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:37:27 -0800] "GET /twiki/bin/view/TWiki/DontNotify HTTP/1.1" 200 4140', '64.242.88.10', '-', - '2004-03-07T16:37:27-08:00', + '2004-03-08T00:37:27+00:00', 'GET', '/twiki/bin/view/TWiki/DontNotify', '1.1', @@ -327,7 +328,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:39:24 -0800] "GET /twiki/bin/view/Main/TokyoOffice HTTP/1.1" 200 3853', '64.242.88.10', '-', - '2004-03-07T16:39:24-08:00', + '2004-03-08T00:39:24+00:00', 'GET', '/twiki/bin/view/Main/TokyoOffice', '1.1', @@ -338,7 +339,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:43:54 -0800] "GET /twiki/bin/view/Main/MikeMannix HTTP/1.1" 200 3686', '64.242.88.10', '-', - '2004-03-07T16:43:54-08:00', + '2004-03-08T00:43:54+00:00', 'GET', '/twiki/bin/view/Main/MikeMannix', '1.1', @@ -349,7 +350,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:45:56 -0800] "GET /twiki/bin/attach/Main/PostfixCommands HTTP/1.1" 401 12846', '64.242.88.10', '-', - '2004-03-07T16:45:56-08:00', + '2004-03-08T00:45:56+00:00', 'GET', '/twiki/bin/attach/Main/PostfixCommands', '1.1', @@ -360,7 +361,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:47:12 -0800] "GET /robots.txt HTTP/1.1" 200 68', '64.242.88.10', '-', - '2004-03-07T16:47:12-08:00', + '2004-03-08T00:47:12+00:00', 'GET', '/robots.txt', '1.1', @@ -371,7 +372,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:47:46 -0800] "GET /twiki/bin/rdiff/Know/ReadmeFirst?rev1=1.5&rev2=1.4 HTTP/1.1" 200 5724', '64.242.88.10', '-', - '2004-03-07T16:47:46-08:00', + '2004-03-08T00:47:46+00:00', 'GET', '/twiki/bin/rdiff/Know/ReadmeFirst?rev1=1.5&rev2=1.4', '1.1', @@ -382,7 +383,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:49:04 -0800] "GET /twiki/bin/view/Main/TWikiGroups?rev=1.2 HTTP/1.1" 200 5162', '64.242.88.10', '-', - '2004-03-07T16:49:04-08:00', + '2004-03-08T00:49:04+00:00', 'GET', '/twiki/bin/view/Main/TWikiGroups?rev=1.2', '1.1', @@ -393,7 +394,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:50:54 -0800] "GET /twiki/bin/rdiff/Main/ConfigurationVariables HTTP/1.1" 200 59679', '64.242.88.10', '-', - '2004-03-07T16:50:54-08:00', + '2004-03-08T00:50:54+00:00', 'GET', '/twiki/bin/rdiff/Main/ConfigurationVariables', '1.1', @@ -404,7 +405,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:52:35 -0800] "GET /twiki/bin/edit/Main/Flush_service_name?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12851', '64.242.88.10', '-', - '2004-03-07T16:52:35-08:00', + '2004-03-08T00:52:35+00:00', 'GET', '/twiki/bin/edit/Main/Flush_service_name?topicparent=Main.ConfigurationVariables', '1.1', @@ -415,7 +416,7 @@ public static function lines(): array '64.242.88.10 - - [07/Mar/2004:16:53:46 -0800] "GET /twiki/bin/rdiff/TWiki/TWikiRegistration HTTP/1.1" 200 34395', '64.242.88.10', '-', - '2004-03-07T16:53:46-08:00', + '2004-03-08T00:53:46+00:00', 'GET', '/twiki/bin/rdiff/TWiki/TWikiRegistration', '1.1', @@ -426,7 +427,7 @@ public static function lines(): array 'lj1036.inktomisearch.com - - [07/Mar/2004:17:18:36 -0800] "GET /robots.txt HTTP/1.0" 200 68', 'lj1036.inktomisearch.com', '-', - '2004-03-07T17:18:36-08:00', + '2004-03-08T01:18:36+00:00', 'GET', '/robots.txt', '1.0', @@ -437,7 +438,7 @@ public static function lines(): array 'lj1090.inktomisearch.com - - [07/Mar/2004:17:18:41 -0800] "GET /twiki/bin/view/Main/LondonOffice HTTP/1.0" 200 3860', 'lj1090.inktomisearch.com', '-', - '2004-03-07T17:18:41-08:00', + '2004-03-08T01:18:41+00:00', 'GET', '/twiki/bin/view/Main/LondonOffice', '1.0', diff --git a/tests/LineParser/MonologTest.php b/tests/LineParser/MonologTest.php index 4f43f0e..2cd12ee 100644 --- a/tests/LineParser/MonologTest.php +++ b/tests/LineParser/MonologTest.php @@ -11,10 +11,9 @@ Log\Attribute\Monolog\Level, Log\Attribute\Monolog\Message, }; -use Innmind\TimeContinuum\Earth\{ +use Innmind\TimeContinuum\{ Clock, - Format\ISO8601, - Timezone\UTC, + Format, }; use Innmind\Immutable\Str; use PHPUnit\Framework\Attributes\DataProvider; @@ -24,13 +23,15 @@ class MonologTest extends TestCase { public function testInterface() { - $this->assertInstanceOf(LineParser::class, Monolog::of(new Clock)); + $this->assertInstanceOf(LineParser::class, Monolog::of(Clock::live())); } #[DataProvider('lines')] public function testInvokation($line, $time, $channel, $level, $message, $context) { - $parse = Monolog::of(new Clock(new UTC)); + $parse = Monolog::of( + Clock::live()->switch(static fn($timezones) => $timezones->utc()), + ); $log = $parse(Str::of($line))->match( static fn($log) => $log, @@ -38,7 +39,7 @@ public function testInvokation($line, $time, $channel, $level, $message, $contex ); $this->assertInstanceOf(Log::class, $log); - $this->assertSame($time, $log->time()->format(new ISO8601)); + $this->assertSame($time, $log->time()->format(Format::iso8601())); $this->assertInstanceOf( Channel::class, $log @@ -115,7 +116,9 @@ public function testInvokation($line, $time, $channel, $level, $message, $contex public function testDoesntInjectContextAttributeWhenFailingToDecodeJsonString() { - $parse = Monolog::of(new Clock(new UTC)); + $parse = Monolog::of( + Clock::live()->switch(static fn($timezones) => $timezones->utc()), + ); $log = $parse(Str::of('[2017-02-08 07:01:04] php.INFO: User Deprecated: Not quoting the scalar "%innmind_neo4j.entity_factory.aggregate.class%" starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0. {] []'))->match( static fn($log) => $log, @@ -166,7 +169,9 @@ public function testDoesntInjectContextAttributeWhenFailingToDecodeJsonString() public function testDoesntInjectExtraAttributeWhenFailingToDecodeJsonString() { - $parse = Monolog::of(new Clock(new UTC)); + $parse = Monolog::of( + Clock::live()->switch(static fn($timezones) => $timezones->utc()), + ); $log = $parse(Str::of('[2017-02-08 07:01:04] php.INFO: User Deprecated: Not quoting the scalar "%innmind_neo4j.entity_factory.aggregate.class%" starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0. [] {]'))->match( static fn($log) => $log, diff --git a/tests/LogTest.php b/tests/LogTest.php index ac12fe5..0b09ef0 100644 --- a/tests/LogTest.php +++ b/tests/LogTest.php @@ -7,7 +7,7 @@ Log, Log\Attribute, }; -use Innmind\TimeContinuum\Earth\PointInTime\Now; +use Innmind\TimeContinuum\PointInTime; use Innmind\Immutable\{ Set, Str, @@ -19,7 +19,7 @@ class LogTest extends TestCase public function testInterface() { $log = Log::of( - $time = new Now, + $time = PointInTime::now(), $raw = Str::of('foo'), $attributes = Set::of(Attribute\Attribute::of('bar', 42)), ); @@ -34,12 +34,12 @@ public function testInterface() public function testEquals() { $log = Log::of( - new Now, + PointInTime::now(), Str::of('foo'), Set::of(), ); $log2 = Log::of( - new Now, + PointInTime::now(), Str::of('bar'), Set::of(), ); diff --git a/tests/ReaderTest.php b/tests/ReaderTest.php index e643d45..114c6ba 100644 --- a/tests/ReaderTest.php +++ b/tests/ReaderTest.php @@ -7,11 +7,12 @@ Reader, LineParser\Monolog, }; -use Innmind\TimeContinuum\Earth\Clock; -use Innmind\Filesystem\File\Content; -use Innmind\IO\IO; -use Innmind\Stream\Readable\Stream; -use Innmind\Stream\Watch\Select; +use Innmind\TimeContinuum\Clock; +use Innmind\Filesystem\{ + Adapter\Filesystem, + Name, +}; +use Innmind\Url\Path; use Innmind\Immutable\Sequence; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -19,12 +20,13 @@ class ReaderTest extends TestCase { public function testParse() { - $read = Reader::of(Monolog::of(new Clock)); - $file = Content::oneShot( - IO::of(static fn() => Select::waitForever())->readable()->wrap( - Stream::of(\fopen('fixtures/symfony.log', 'r')), - ), - ); + $read = Reader::of(Monolog::of(Clock::live())); + $file = Filesystem::mount(Path::of('fixtures/')) + ->get(Name::of('symfony.log')) + ->match( + static fn($file) => $file->content(), + static fn() => null, + ); $stream = $read($file);