Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Changed

- Requires `innmind/foundation:~1.3`

### Fixed

- PHP `8.4` deprecations
Expand Down
9 changes: 2 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 0 additions & 18 deletions src/LineParser/Apache/TimeFormat.php

This file was deleted.

5 changes: 4 additions & 1 deletion src/LineParser/ApacheAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use Innmind\TimeContinuum\{
Clock,
PointInTime,
Format,
};
use Innmind\Url\{
Url,
Authority\Host,
};
use Innmind\Validation\Is;
use Innmind\Http\{
ProtocolVersion,
Method,
Expand Down Expand Up @@ -60,7 +62,8 @@ public function __invoke(Str $line): Maybe
$time = $parts
->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));
Expand Down
9 changes: 7 additions & 2 deletions src/LineParser/Monolog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
65 changes: 33 additions & 32 deletions tests/LineParser/ApacheAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
LineParser,
Log,
};
use Innmind\TimeContinuum\Earth\{
use Innmind\TimeContinuum\{
Clock,
Timezone\UTC,
Format\ISO8601,
Format,
};
use Innmind\Http\{
Method,
Expand All @@ -30,21 +29,23 @@ 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,
static fn() => null,
);

$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
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
Loading
Loading