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,23 +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 (isset ($ data ['id ' ])) {
47
- $ person = call_user_func ($ config ['person_fn ' ]);
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 ;
54
+ }
55
+ }
56
+ } elseif (is_array ($ data ) && isset ($ data ['id ' ])) {
57
+ $ person = $ data ;
48
58
}
49
59
}
60
+ unset($ data );
50
61
}
51
62
52
63
// Add user session information.
@@ -60,7 +71,7 @@ protected function addContext(array $context = [])
60
71
if (! isset ($ person ['id ' ])) {
61
72
$ person ['id ' ] = $ this ->app ->session ->getId ();
62
73
}
63
-
74
+
64
75
$ this ->rollbarLogger ->configure (['person ' => $ person ]);
65
76
}
66
77
0 commit comments