|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Bouncer package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) François Hodierne <[email protected]> |
|
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 Bouncer\Logger; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Base Logger class providing the Cache structure |
|
16
|
|
|
* |
|
17
|
|
|
* @author François Hodierne <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class BaseLogger |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
public function format(array $logEntry) |
|
23
|
|
|
{ |
|
24
|
|
|
$formattedEntry = array(); |
|
25
|
|
|
|
|
26
|
|
|
if (isset($logEntry['address'])) { |
|
27
|
|
|
$formattedEntry['address'] = $this->formatAddress($logEntry['address']); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if (isset($logEntry['request'])) { |
|
31
|
|
|
$formattedEntry['request'] = $this->formatRequest($logEntry['request']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (isset($logEntry['response'])) { |
|
35
|
|
|
$formattedEntry['response'] = $logEntry['response']; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (isset($logEntry['context'])) { |
|
39
|
|
|
$formattedEntry['context']['bouncer'] = $logEntry['context']; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (isset($logEntry['key'])) { |
|
43
|
|
|
$formattedEntry['key'] = $logEntry['key']; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (isset($logEntry['session'])) { |
|
47
|
|
|
$formattedEntry['session'] = $logEntry['session']; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $formattedEntry; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function formatAddress($address) |
|
54
|
|
|
{ |
|
55
|
|
|
if (is_object($address)) { |
|
56
|
|
|
return $address->getValue(); |
|
57
|
|
|
} elseif (is_array($address)) { |
|
58
|
|
|
return $address['value']; |
|
59
|
|
|
} elseif (is_string($address)) { |
|
60
|
|
|
return $address; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function formatRequest($request) |
|
65
|
|
|
{ |
|
66
|
|
|
if (is_object($request)) { |
|
67
|
|
|
return $request->toArray(); |
|
68
|
|
|
} elseif (is_array($request)) { |
|
69
|
|
|
return $request; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|