Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
UserAwareLogger | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
createEntry | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
setAuth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Logger; |
6 | |
7 | use Engelsystem\Helpers\Authenticator; |
8 | |
9 | class UserAwareLogger extends Logger |
10 | { |
11 | protected ?Authenticator $auth; |
12 | |
13 | /** |
14 | * Adds the authenticated user to the log message |
15 | */ |
16 | public function createEntry(array $data): void |
17 | { |
18 | if ($this->auth && ($user = $this->auth->user())) { |
19 | $data['user_id'] = $user->id; |
20 | } |
21 | |
22 | parent::createEntry($data); |
23 | } |
24 | |
25 | public function setAuth(Authenticator $auth): void |
26 | { |
27 | $this->auth = $auth; |
28 | } |
29 | } |