1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the XiideaEasyAuditBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Xiidea <http://www.xiidea.net> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xiidea\EasyAuditBundle\Model; |
13
|
|
|
|
14
|
|
|
use Psr\Log\InvalidArgumentException; |
15
|
|
|
use Psr\Log\LogLevel; |
16
|
|
|
use Xiidea\EasyAuditBundle\Traits\EntityHydrationMethod; |
17
|
|
|
|
18
|
|
|
class BaseAuditLog |
19
|
|
|
{ |
20
|
|
|
use EntityHydrationMethod; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $typeId; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $type; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $description; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \DateTime |
39
|
|
|
*/ |
40
|
|
|
protected $eventTime; |
41
|
|
|
|
42
|
|
|
protected $user; |
43
|
|
|
|
44
|
|
|
protected $impersonatingUser; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected $ip; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $level = LogLevel::INFO; |
55
|
|
|
|
56
|
|
|
public function getUser() |
57
|
|
|
{ |
58
|
|
|
return $this->user; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setUser($user) |
62
|
|
|
{ |
63
|
|
|
$this->user = $user; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \DateTime |
68
|
|
|
*/ |
69
|
|
|
final public function getEventTime() |
70
|
|
|
{ |
71
|
|
|
return $this->eventTime; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param \DateTime $eventTime |
76
|
|
|
*/ |
77
|
|
|
final public function setEventTime(\DateTime $eventTime) |
78
|
|
|
{ |
79
|
|
|
$this->eventTime = $eventTime; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getType() |
86
|
|
|
{ |
87
|
|
|
return $this->type; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $type |
92
|
|
|
*/ |
93
|
|
|
public function setType($type) |
94
|
|
|
{ |
95
|
|
|
$this->type = $type; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getDescription() |
102
|
|
|
{ |
103
|
|
|
return $this->description; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $description |
108
|
|
|
*/ |
109
|
|
|
public function setDescription($description) |
110
|
|
|
{ |
111
|
|
|
$this->description = $description; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getTypeId() |
118
|
|
|
{ |
119
|
|
|
return $this->typeId; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $typeId |
124
|
|
|
* |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
|
|
public function setTypeId($typeId) |
128
|
|
|
{ |
129
|
|
|
$this->typeId = $typeId; |
130
|
|
|
|
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function getIp() |
138
|
|
|
{ |
139
|
|
|
return $this->ip; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param string $ip |
144
|
|
|
* |
145
|
|
|
* @return $this |
146
|
|
|
*/ |
147
|
|
|
public function setIp($ip) |
148
|
|
|
{ |
149
|
|
|
$this->ip = $ip; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
final public function getLevel() |
158
|
|
|
{ |
159
|
|
|
return $this->level; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param string $level |
164
|
|
|
* |
165
|
|
|
* @return $this |
166
|
|
|
*/ |
167
|
|
|
final public function setLevel($level) |
168
|
|
|
{ |
169
|
|
|
if (!in_array(strtolower($level), $this->getAllowedLevel())) { |
170
|
|
|
throw new InvalidArgumentException(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->level = $level; |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
private function getAllowedLevel() |
179
|
|
|
{ |
180
|
|
|
$oClass = new \ReflectionClass('Psr\Log\LogLevel'); |
181
|
|
|
|
182
|
|
|
return $oClass->getConstants(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return mixed |
187
|
|
|
*/ |
188
|
|
|
public function getImpersonatingUser() |
189
|
|
|
{ |
190
|
|
|
return $this->impersonatingUser; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param mixed $impersonatingUser |
195
|
|
|
*/ |
196
|
|
|
public function setImpersonatingUser($impersonatingUser) |
197
|
|
|
{ |
198
|
|
|
$this->impersonatingUser = $impersonatingUser; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|