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
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
namespace MediaWiki\Notification;
use MediaWiki\Notification\Types\WikiNotification;
use Wikimedia\JsonCodec\JsonCodecable;
use Wikimedia\NonSerializable\NonSerializableTrait;
/**
* @since 1.44
* @unstable
*/
class Notification {
use NonSerializableTrait;
/**
* @TODO Idea: handle future types in format `namespace.type`, like `mediawiki.message`,
* `growth.welcome`. This way we can easily "override" some notifications, for example,
* we can have `echo.mention`, and the `echo.mention` could supersede `mediawiki.mention`. Also,
* it will be more difficult for notifications to conflict, and we will be able to easily filter
* apply logic depends on the namespace (for example, hide if extension not present).
*
* @var string Required, Read-only - The Notification type
*/
protected string $type;
/**
* Internal, for now let's allow extensions to use generic notification and pass everything in
* custom array, but in future the notifications should have specific types.
* @var array An array of mixed data
*/
private array $custom;
/**
* Base for Notifications. Type is the only required property, and any additional data can be
* passed via $custom array.
*
* @see WikiNotification in case you want a Notification with Agent and Title
* @param string $type Notification type
* @param (scalar|array|null|JsonCodecable)[] $custom Custom notification data, see
* setProperty() for more details about the allowed keys and values
*/
public function __construct( string $type, array $custom = [] ) {
$this->type = $type;
$this->custom = $custom;
}
/**
* Get the Notification type
*/
public function getType(): string {
return $this->type;
}
/**
* Sets a custom property to the notification.
*
* Any other keys may be used to pass additional data handled by specific extensions.*
* The value of keys other than those listed above should be (de)serializable as JSON, by either
* being scalar or array containing scalar values or using the JsonCodecable interface.
*
* @param string $key
* @param scalar|array|JsonCodecable $value
*/
public function setProperty( string $key, $value ): void {
$this->custom[$key] = $value;
}
/**
* Retrieve Notification properties
*/
public function getProperties(): array {
return $this->custom;
}
}
|