scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | <?php |
2 | |||
3 | /* |
||
4 | * This file is part of the Monolog package. |
||
5 | * |
||
6 | * (c) Jordi Boggiano <j.boggiano@seld.be> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Monolog\Processor; |
||
13 | |||
14 | /** |
||
15 | * Processes a record's message according to PSR-3 rules |
||
16 | * |
||
17 | * It replaces {foo} with the value from $context['foo'] |
||
18 | * |
||
19 | * @author Jordi Boggiano <j.boggiano@seld.be> |
||
20 | */ |
||
21 | class PsrLogMessageProcessor |
||
22 | { |
||
23 | /** |
||
24 | * @param array $record |
||
25 | * @return array |
||
26 | */ |
||
27 | public function __invoke(array $record) |
||
28 | { |
||
29 | if (false === strpos($record['message'], '{')) { |
||
30 | return $record; |
||
31 | } |
||
32 | |||
33 | $replacements = array(); |
||
34 | foreach ($record['context'] as $key => $val) { |
||
35 | if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) { |
||
36 | $replacements['{'.$key.'}'] = $val; |
||
37 | } elseif (is_object($val)) { |
||
38 | $replacements['{'.$key.'}'] = '[object '.get_class($val).']'; |
||
39 | } else { |
||
40 | $replacements['{'.$key.'}'] = '['.gettype($val).']'; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | $record['message'] = strtr($record['message'], $replacements); |
||
45 | |||
46 | return $record; |
||
47 | } |
||
48 | } |