1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Sco\ActionLog\Events; |
5
|
|
|
|
6
|
|
|
use Auth; |
7
|
|
|
use Request; |
8
|
|
|
use Sco\ActionLog\LogInfo; |
9
|
|
|
|
10
|
|
|
abstract class Event implements EventInterface |
11
|
|
|
{ |
12
|
|
|
protected $type; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var \Sco\ActionLog\LogInfo |
16
|
|
|
*/ |
17
|
|
|
public $logInfo; |
18
|
|
|
|
19
|
|
|
abstract protected function getContent(); |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$this->setLogInfo(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function getType() |
27
|
|
|
{ |
28
|
|
|
return $this->type; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function getClient() |
32
|
|
|
{ |
33
|
|
|
if (class_exists('\Jenssegers\Agent\Agent')) { |
34
|
|
|
$agent = new \Jenssegers\Agent\Agent(); |
35
|
|
|
|
36
|
|
|
$platform = $agent->platform(); |
37
|
|
|
$browser = $agent->browser(); |
38
|
|
|
|
39
|
|
|
return [ |
40
|
|
|
'device' => $agent->device(), |
41
|
|
|
'platform' => $platform . ' ' . $agent->version($platform), |
42
|
|
|
'browser' => $browser . ' ' . $agent->version($browser), |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return [ |
47
|
|
|
'agent' => Request::header('User-Agent'), |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function setLogInfo() |
52
|
|
|
{ |
53
|
|
|
$this->logInfo = new LogInfo([ |
54
|
|
|
'type' => $this->getType(), |
55
|
|
|
'content' => $this->getContent(), |
56
|
|
|
'client_ip' => Request::getClientIp(), |
57
|
|
|
'client' => $this->getClient(), |
58
|
|
|
'user_id' => intval(Auth::id()), |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
return $this->logInfo; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return \Sco\ActionLog\LogInfo |
66
|
|
|
*/ |
67
|
|
|
public function getLogInfo() |
68
|
|
|
{ |
69
|
|
|
return $this->logInfo; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|