-
-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathLogFileCollection.php
45 lines (36 loc) · 1.04 KB
/
LogFileCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Opcodes\LogViewer;
use Illuminate\Support\Collection;
use Opcodes\LogViewer\Readers\MultipleLogReader;
/**
* @var LogFile[] $items
*/
class LogFileCollection extends Collection
{
public function sortByEarliestFirst(): self
{
$this->items = $this->sortBy(function (LogFile $file) {
return $file->earliestTimestamp().($file->name ?? '');
}, SORT_NATURAL)->values()->toArray();
return $this;
}
public function sortByLatestFirst(): self
{
$this->items = $this->sortByDesc(function (LogFile $file) {
return $file->latestTimestamp().($file->name ?? '');
}, SORT_NATURAL)->values()->toArray();
return $this;
}
public function latest(): ?LogFile
{
return $this->sortByDesc->latestTimestamp()->first();
}
public function earliest(): ?LogFile
{
return $this->sortBy->earliestTimestamp()->first();
}
public function logs(): MultipleLogReader
{
return new MultipleLogReader($this->items);
}
}