blob: 264a393991fa43ce949becd10e26f4bc79d22da9 (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Log\Formatter;
use Monolog\Formatter\FormatterInterface;
use Piwik\Log;
/**
* Formats a log message.
*
* Follows the Chain of responsibility design pattern, so don't forget to call `$this->next(...)`
* at the end of the `format()` method.
*/
abstract class Formatter implements FormatterInterface
{
/**
* @var Formatter|null
*/
protected $next;
/**
* {@inheritdoc}
*/
public abstract function format(array $record);
/**
* {@inheritdoc}
*/
public function formatBatch(array $records)
{
foreach ($records as $key => $record) {
$records[$key] = $this->format($record);
}
return $records;
}
/**
* Chain of responsibility pattern.
*
* @param Formatter $formatter
*/
public function setNext(Formatter $formatter)
{
$this->next = $formatter;
}
protected function next(array $record)
{
if (! $this->next) {
return $record;
}
return $this->next->format($record);
}
}
|