1 | <?php |
||
2 | namespace Elgg\Notifications; |
||
3 | |||
4 | use ElggData; |
||
5 | use ElggEntity; |
||
6 | use InvalidArgumentException; |
||
7 | use stdClass; |
||
8 | |||
9 | /** |
||
10 | * Subscription notification event |
||
11 | * |
||
12 | * @package Elgg.Core |
||
13 | * @subpackage Notifications |
||
14 | * @deprecated 2.3 |
||
15 | */ |
||
16 | class Event implements NotificationEvent { |
||
17 | |||
18 | use EventSerialization; |
||
19 | |||
20 | /* @var string The name of the action/event */ |
||
21 | protected $action; |
||
22 | |||
23 | /* @var string Action's object */ |
||
24 | protected $object; |
||
25 | |||
26 | /* @var ElggEntity User who triggered the event */ |
||
27 | protected $actor; |
||
28 | |||
29 | /** |
||
30 | * Create a notification event |
||
31 | * |
||
32 | * @param ElggData $object The object of the event (ElggEntity) |
||
33 | * @param string $action The name of the action (default: create) |
||
34 | * @param ElggEntity $actor The entity that caused the event (default: logged in user) |
||
35 | * |
||
36 | * @throws InvalidArgumentException |
||
37 | */ |
||
38 | 49 | public function __construct(ElggData $object, $action, ElggEntity $actor = null) { |
|
39 | 49 | if (get_class($this) == Event::class) { |
|
40 | _elgg_services()->deprecation->sendNotice(__CLASS__ . ' is deprecated. ' |
||
41 | . 'Use ' . SubscriptionNotificationEvent::class . ' instead', '2.3'); |
||
42 | } |
||
43 | 49 | if (!$object instanceof ElggData) { |
|
44 | throw new InvalidArgumentException(__METHOD__ . ' expects an object as an instance of ' . ElggData::class); |
||
45 | } |
||
46 | 49 | if (!$action) { |
|
47 | throw new InvalidArgumentException(__METHOD__ . ' expects a valid action name'); |
||
48 | } |
||
49 | |||
50 | 49 | $this->object = $object; |
|
0 ignored issues
–
show
|
|||
51 | |||
52 | 49 | $this->actor = $actor; |
|
53 | 49 | if (!isset($actor)) { |
|
54 | 49 | $this->actor = _elgg_services()->session->getLoggedInUser(); |
|
55 | } |
||
56 | |||
57 | 49 | $this->action = $action; |
|
58 | 49 | } |
|
59 | |||
60 | /** |
||
61 | * Get the actor of the event |
||
62 | * |
||
63 | * @note Note that the actor and the object of the notification event |
||
64 | * may have been deleted/disabled since the event was serialized and |
||
65 | * stored in the database. |
||
66 | * |
||
67 | * @return ElggEntity|false|null |
||
68 | */ |
||
69 | 30 | public function getActor() { |
|
70 | 30 | return $this->actor; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Get the GUID of the actor |
||
75 | * |
||
76 | * @note Note that the actor and the object of the notification event |
||
77 | * may have been deleted/disabled since the event was serialized and |
||
78 | * stored in the database. |
||
79 | * |
||
80 | * @return int |
||
81 | */ |
||
82 | 18 | public function getActorGUID() { |
|
83 | 18 | return $this->actor ? $this->actor->guid : 0; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * Get the object of the event |
||
88 | * |
||
89 | * @note Note that the actor and the object of the notification event |
||
90 | * may have been deleted/disabled since the event was serialized and |
||
91 | * stored in the database. |
||
92 | * |
||
93 | * @return ElggData|false|null |
||
94 | */ |
||
95 | 30 | public function getObject() { |
|
96 | 30 | return $this->object; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get the name of the action |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 18 | public function getAction() { |
|
105 | 18 | return $this->action; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Get a description of the event |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 30 | public function getDescription() { |
|
114 | 30 | return implode(':', [ |
|
115 | 30 | $this->action, |
|
116 | 30 | $this->object->getType(), |
|
117 | 30 | $this->object->getSubtype(), |
|
118 | ]); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Export the notification event into a serializable object |
||
123 | * This method is mainly used for logging purposes |
||
124 | * |
||
125 | * @return stdClass |
||
126 | */ |
||
127 | public function toObject() { |
||
128 | $obj = new stdClass(); |
||
129 | $vars = get_object_vars($this); |
||
130 | foreach ($vars as $key => $value) { |
||
131 | if (is_object($value) && is_callable([$value, 'toObject'])) { |
||
132 | $obj->$key = $value->toObject(); |
||
133 | } else { |
||
134 | $obj->$key = $value; |
||
135 | } |
||
136 | } |
||
137 | return $obj; |
||
138 | } |
||
139 | } |
||
140 | |||
141 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..