Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Formatter.php « Formatter « Log « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 66de41423c633755c1f039af9396d044324ebe89 (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
<?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 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
{
    /**
     * @var Formatter|null
     */
    protected $next;

    /**
     * @param array $record
     * @param Log $logger
     *
     * @return array Updated record.
     */
    public abstract function format(array $record, Log $logger);

    /**
     * Chain of responsibility pattern.
     *
     * @param Formatter $formatter
     */
    public function setNext(Formatter $formatter)
    {
        $this->next = $formatter;
    }

    protected function next(array $record, Log $logger)
    {
        if (! $this->next) {
            return $record;
        }

        return $this->next->format($record, $logger);
    }
}