-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalysableLog.php
50 lines (43 loc) · 1.16 KB
/
AnalysableLog.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
46
47
48
49
50
<?php
namespace Aternos\Codex\Log;
use Aternos\Codex\Analyser\AnalyserInterface;
use Aternos\Codex\Analysis\AnalysisInterface;
/**
* Class AnalysableLog
*
* @package Aternos\Codex\Log
*/
abstract class AnalysableLog extends Log implements AnalysableLogInterface
{
protected ?AnalysisInterface $analysis = null;
/**
* Analyse a log file with an analyser
*
* Every log type should have a default analyser,
* but the $analyser argument can be used to override
* the default analyser
*
* @param AnalyserInterface|null $analyser
* @return AnalysisInterface
*/
public function analyse(?AnalyserInterface $analyser = null): AnalysisInterface
{
if ($this->analysis !== null) {
return $this->analysis;
}
if ($analyser === null) {
$analyser = static::getDefaultAnalyser();
}
$analyser->setLog($this);
return $this->analysis = $analyser->analyse();
}
/**
* @return array
*/
public function jsonSerialize(): array
{
return array_merge(parent::jsonSerialize(), [
'analysis' => $this->analyse()
]);
}
}