|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\mongodb_watchdog; |
|
4
|
|
|
|
|
5
|
|
|
use MongoDB\BSON\Unserializable; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Event. |
|
9
|
|
|
* |
|
10
|
|
|
* @package Drupal\mongodb_watchdog |
|
11
|
|
|
*/ |
|
12
|
|
|
class Event implements Unserializable { |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
// @codingStandardsIgnoreStart |
|
15
|
|
|
/** |
|
16
|
|
|
* The string representation of a MongoId. |
|
17
|
|
|
* |
|
18
|
|
|
* @var int |
|
19
|
|
|
*/ |
|
20
|
|
|
public $_id; |
|
21
|
|
|
// @codingStandardsIgnoreEnd |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* User id. |
|
25
|
|
|
* |
|
26
|
|
|
* @var int |
|
27
|
|
|
*/ |
|
28
|
|
|
public $uid; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Event type, often a module name. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
public $type; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Event template. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
public $message; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The template parameters. |
|
46
|
|
|
* |
|
47
|
|
|
* @var array |
|
48
|
|
|
*/ |
|
49
|
|
|
public $variables; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* A RFC5424 severity level. |
|
53
|
|
|
* |
|
54
|
|
|
* @var int |
|
55
|
|
|
*/ |
|
56
|
|
|
public $severity; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* A link provided by the event emitter. Optional. |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
public $link; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* The absolute URL for the path on which the event was logged. |
|
67
|
|
|
* |
|
68
|
|
|
* @var string |
|
69
|
|
|
*/ |
|
70
|
|
|
public $location; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* A HTTP referrer for the path on which the event was logged. Optional. |
|
74
|
|
|
* |
|
75
|
|
|
* @var string |
|
76
|
|
|
*/ |
|
77
|
|
|
public $referrer; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* The server host. |
|
81
|
|
|
* |
|
82
|
|
|
* @var string |
|
83
|
|
|
*/ |
|
84
|
|
|
public $hostname; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* The timestamp at which the event was logged. |
|
88
|
|
|
* |
|
89
|
|
|
* @var int |
|
90
|
|
|
*/ |
|
91
|
|
|
public $timestamp; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Constructor. |
|
95
|
|
|
* |
|
96
|
|
|
* @param array $event |
|
97
|
|
|
* The event in array form. |
|
98
|
|
|
*/ |
|
99
|
|
|
public function __construct(array $event) { |
|
100
|
|
|
$keys = [ |
|
101
|
|
|
'_id', |
|
102
|
|
|
'hostname', |
|
103
|
|
|
'link', |
|
104
|
|
|
'location', |
|
105
|
|
|
'message', |
|
106
|
|
|
'referrer', |
|
107
|
|
|
'severity', |
|
108
|
|
|
'timestamp', |
|
109
|
|
|
'type', |
|
110
|
|
|
'uid', |
|
111
|
|
|
'variables', |
|
112
|
|
|
]; |
|
113
|
|
|
foreach ($keys as $key) { |
|
114
|
|
|
if (isset($event[$key])) { |
|
115
|
|
|
$this->$key = $event[$key]; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Load a MongoDB watchdog event. |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $id |
|
|
|
|
|
|
124
|
|
|
* The string representation of a MongoId. |
|
125
|
|
|
* |
|
126
|
|
|
* @return \Drupal\mongodb_watchdog\Event|bool |
|
127
|
|
|
* FALSE if the event cannot be loaded. |
|
128
|
|
|
*/ |
|
129
|
|
|
public function find($template_id) { |
|
130
|
|
|
$criteria = ['_id' => new ObjectID($id)]; |
|
|
|
|
|
|
131
|
|
|
$options = [ |
|
132
|
|
|
'typeMap' => [ |
|
133
|
|
|
'array' => 'array', |
|
134
|
|
|
'document' => 'array', |
|
135
|
|
|
'root' => 'Drupal\mongodb_watchdog\Event', |
|
136
|
|
|
], |
|
137
|
|
|
]; |
|
138
|
|
|
|
|
139
|
|
|
$result = $this->templatesCollection->findOne($criteria, $options); |
|
140
|
|
|
var_dump($result); |
|
|
|
|
|
|
141
|
|
|
return $result; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
function bsonUnserialize(array $data) { |
|
|
|
|
|
|
145
|
|
|
$event = new static($data); |
|
146
|
|
|
return $event; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
|
|
|
|
|
149
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.