|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Drupal\mongodb_watchdog; |
|
6
|
|
|
|
|
7
|
|
|
use Drupal\Core\Logger\RfcLogLevel; |
|
|
|
|
|
|
8
|
|
|
use MongoDB\BSON\ObjectIdInterface; |
|
9
|
|
|
use MongoDB\BSON\Unserializable; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Event is a value object for a logged event. |
|
13
|
|
|
* |
|
14
|
|
|
* @package Drupal\mongodb_watchdog |
|
15
|
|
|
* |
|
16
|
|
|
* Since this is essentially a value object, naming is constrained by the |
|
17
|
|
|
* property names in MongoDB, so ignore variable naming rules for fields. |
|
18
|
|
|
* |
|
19
|
|
|
* @SuppressWarnings(PHPMD.CamelCasePropertyName) |
|
20
|
|
|
* @SuppressWarnings(Variable) |
|
21
|
|
|
*/ |
|
22
|
|
|
class Event implements Unserializable { |
|
23
|
|
|
const KEYS = [ |
|
24
|
|
|
'_id', |
|
25
|
|
|
'hostname', |
|
26
|
|
|
'link', |
|
27
|
|
|
'location', |
|
28
|
|
|
'message', |
|
29
|
|
|
'referrer', |
|
30
|
|
|
'severity', |
|
31
|
|
|
'timestamp', |
|
32
|
|
|
'type', |
|
33
|
|
|
'uid', |
|
34
|
|
|
'variables', |
|
35
|
|
|
'requestTracking_id', |
|
36
|
|
|
'requestTracking_sequence', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
// @codingStandardsIgnoreStart |
|
40
|
|
|
/** |
|
41
|
|
|
* A MongoId. |
|
42
|
|
|
* |
|
43
|
|
|
* @var \MongoDB\BSON\ObjectIdInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
public ObjectIdInterface $_id; |
|
46
|
|
|
// @codingStandardsIgnoreEnd |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* User id. Use uid() instead for type safety. |
|
50
|
|
|
* |
|
51
|
|
|
* @var ?int |
|
52
|
|
|
*/ |
|
53
|
|
|
public ?int $uid = 0; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Event type, often a module name. |
|
57
|
|
|
* |
|
58
|
|
|
* @var ?string |
|
59
|
|
|
*/ |
|
60
|
|
|
public ?string $type; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Event template. |
|
64
|
|
|
* |
|
65
|
|
|
* @var ?string |
|
66
|
|
|
*/ |
|
67
|
|
|
public ?string $message; |
|
68
|
|
|
|
|
69
|
|
|
// @codingStandardsIgnoreStart |
|
70
|
|
|
/** |
|
71
|
|
|
* The identifier of the request during which this event occurred. |
|
72
|
|
|
* |
|
73
|
|
|
* Coding standards are suspended for requestTracking_id which is required by |
|
74
|
|
|
* the MongoDB property. |
|
75
|
|
|
* |
|
76
|
|
|
* @var ?string |
|
77
|
|
|
*/ |
|
78
|
|
|
public ?string $requestTracking_id; |
|
79
|
|
|
// @codingStandardsIgnoreEnd |
|
80
|
|
|
|
|
81
|
|
|
// @codingStandardsIgnoreStart |
|
82
|
|
|
/** |
|
83
|
|
|
* The sequence number of the event during the request when it happened. |
|
84
|
|
|
* |
|
85
|
|
|
* Coding standards are suspended for requestTracking_sequence which is |
|
86
|
|
|
* required by the MongoDB property. |
|
87
|
|
|
* |
|
88
|
|
|
* @var ?int |
|
89
|
|
|
*/ |
|
90
|
|
|
public ?int $requestTracking_sequence = 0; |
|
91
|
|
|
// @codingStandardsIgnoreEnd |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* The template parameters. |
|
95
|
|
|
* |
|
96
|
|
|
* @var ?array<string,mixed> |
|
97
|
|
|
*/ |
|
98
|
|
|
public ?array $variables = []; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* A RFC5424 severity level. |
|
102
|
|
|
* |
|
103
|
|
|
* @var ?int |
|
104
|
|
|
*/ |
|
105
|
|
|
public ?int $severity = RfcLogLevel::DEBUG; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* A link provided by the event emitter. Optional. |
|
109
|
|
|
* |
|
110
|
|
|
* @var ?string |
|
111
|
|
|
*/ |
|
112
|
|
|
public ?string $link; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* The absolute URL for the path on which event was logged. Use location(). |
|
116
|
|
|
* |
|
117
|
|
|
* @var ?string |
|
118
|
|
|
*/ |
|
119
|
|
|
public ?string $location; |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* A HTTP referrer for the path on which the event was logged. Optional. |
|
123
|
|
|
* |
|
124
|
|
|
* @var ?string |
|
125
|
|
|
*/ |
|
126
|
|
|
public ?string $referrer; |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* The server host. |
|
130
|
|
|
* |
|
131
|
|
|
* @var ?string |
|
132
|
|
|
*/ |
|
133
|
|
|
public ?string $hostname; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* The timestamp at which the event was logged. |
|
137
|
|
|
* |
|
138
|
|
|
* @var ?int |
|
139
|
|
|
*/ |
|
140
|
|
|
public ?int $timestamp = 0; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Constructor. |
|
144
|
|
|
* |
|
145
|
|
|
* @param array<mixed,mixed> $event |
|
146
|
|
|
* The event in array form. |
|
147
|
|
|
*/ |
|
148
|
|
|
public function __construct(array $event) { |
|
149
|
|
|
$this->bsonUnserialize($event); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* {@inheritdoc} |
|
154
|
|
|
* |
|
155
|
|
|
* @param array<mixed,mixed> $data |
|
156
|
|
|
* The raw data, from which we will only pick up those we want. |
|
157
|
|
|
*/ |
|
158
|
|
|
public function bsonUnserialize(array $data): void { |
|
159
|
|
|
foreach (static::KEYS as $key) { |
|
160
|
|
|
if (isset($data[$key])) { |
|
161
|
|
|
$this->{$key} = $data[$key]; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Type-safe getter for location. |
|
168
|
|
|
* |
|
169
|
|
|
* @return string |
|
170
|
|
|
* The location property, always as a string, never NULL. |
|
171
|
|
|
*/ |
|
172
|
|
|
public function location(): string { |
|
173
|
|
|
return $this->location ?? ''; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Type-safe getter for uid. |
|
178
|
|
|
* |
|
179
|
|
|
* @return int |
|
180
|
|
|
* The uid property, always as an int, never NULL. |
|
181
|
|
|
*/ |
|
182
|
|
|
public function uid(): int { |
|
183
|
|
|
return $this->uid ?? 0; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths