/
Concrete5UserProcessor.php
65 lines (51 loc) · 1.17 KB
/
Concrete5UserProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Concrete\Core\Logging\Processor;
use Concrete\Core\Application\Application;
use Concrete\Core\User\User;
/**
* A processor for adding the concrete5 user into the extra log info
*/
class Concrete5UserProcessor
{
/**
* @var Application
*/
protected $app;
/**
* The cached user instance
*
* @var User|null
*/
protected $user;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Invoke this processor
*
* @param array $record The given monolog record
*
* @return array The modified record
*/
public function __invoke(array $record)
{
$user = $this->getLoggedInUser();
if ($user && $user->isRegistered()) {
$record['extra']['user'] = [$user->getUserID(), $user->getUserName()];
}
return $record;
}
/**
* Resolve a user intance from the IOC container and cache it
*
* @return User|mixed
*/
protected function getLoggedInUser()
{
if (!$this->user) {
$this->user = $this->app->make(User::class);
}
return $this->user;
}
}