7
7
class MonologHandler extends RollbarHandler
8
8
{
9
9
protected $ app ;
10
-
10
+
11
11
public function setApp ($ app )
12
12
{
13
13
$ this ->app = $ app ;
14
14
}
15
-
15
+
16
16
protected function write (array $ record )
17
17
{
18
18
$ record ['context ' ] = $ this ->addContext ($ record ['context ' ]);
@@ -30,32 +30,34 @@ protected function addContext(array $context = [])
30
30
if ($ session = $ this ->app ->session ->all ()) {
31
31
$ config = $ this ->rollbarLogger ->extend ([]);
32
32
33
- if (empty ($ config ['person ' ]) or ! is_array ($ config ['person ' ])) {
33
+ if (empty ($ config ['person ' ]) || ! is_array ($ config ['person ' ])) {
34
34
$ person = [];
35
35
} else {
36
36
$ person = $ config ['person ' ];
37
37
}
38
38
39
39
// Merge person context.
40
- if (isset ($ context ['person ' ]) and is_array ($ context ['person ' ])) {
40
+ if (isset ($ context ['person ' ]) && is_array ($ context ['person ' ])) {
41
41
$ person = $ context ['person ' ];
42
42
unset($ context ['person ' ]);
43
- } else {
44
- if (isset ($ config ['person_fn ' ]) && is_callable ($ config ['person_fn ' ])) {
45
- $ data = @call_user_func ($ config ['person_fn ' ]);
46
- if (! empty ($ data )) {
47
- if (is_object ($ data )) {
48
- if (method_exists ($ data , 'toArray ' )) {
49
- $ data = $ data ->toArray ();
50
- } else {
51
- $ data = (array )$ data ;
43
+ } elseif (isset ($ config ['person_fn ' ]) && is_callable ($ config ['person_fn ' ])) {
44
+ $ data = @call_user_func ($ config ['person_fn ' ]);
45
+ if (! empty ($ data )) {
46
+ if (is_object ($ data )) {
47
+ if (isset ($ data ->id )) {
48
+ $ person ['id ' ] = $ data ->id ;
49
+ if (isset ($ data ->username )) {
50
+ $ person ['username ' ] = $ data ->username ;
51
+ }
52
+ if (isset ($ data ->email )) {
53
+ $ person ['email ' ] = $ data ->email ;
52
54
}
53
55
}
54
- if (isset ($ data ['id ' ])) {
55
- $ person = $ data ;
56
- }
56
+ } elseif (is_array ($ data ) && isset ($ data ['id ' ])) {
57
+ $ person = $ data ;
57
58
}
58
59
}
60
+ unset($ data );
59
61
}
60
62
61
63
// Add user session information.
@@ -69,7 +71,7 @@ protected function addContext(array $context = [])
69
71
if (! isset ($ person ['id ' ])) {
70
72
$ person ['id ' ] = $ this ->app ->session ->getId ();
71
73
}
72
-
74
+
73
75
$ this ->rollbarLogger ->configure (['person ' => $ person ]);
74
76
}
75
77
0 commit comments