blob: 338efc15e117096259e40c3ccbe46ef56c4c4b4a (
plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
<?php
namespace gipfl\Protocol\JsonRpc;
class Notification extends Packet
{
/** @var string */
protected $method;
/** @var \stdClass|array */
protected $params;
public function __construct($method, $params)
{
$this->setMethod($method);
$this->setParams($params);
}
/**
* @return string
*/
public function getMethod()
{
return $this->method;
}
/**
* @param string $method
*/
public function setMethod($method)
{
$this->method = $method;
}
/**
* @return object|array
*/
public function getParams()
{
return $this->params;
}
/**
* @param object|array $params
*/
public function setParams($params)
{
$this->params = $params;
}
/**
* @param string $name
* @param mixed $default
* @return mixed|null
*/
public function getParam($name, $default = null)
{
$p = & $this->params;
if (\is_object($p) && \property_exists($p, $name)) {
return $p->$name;
} elseif (\is_array($p) && \array_key_exists($name, $p)) {
return $p[$name];
}
return $default;
}
/**
* @return object
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
$plain = [
'jsonrpc' => '2.0',
'method' => $this->method,
'params' => $this->params,
];
if ($this->hasExtraProperties()) {
$plain += (array) $this->getExtraProperties();
}
return (object) $plain;
}
/**
* @param $method
* @param $params
* @return static
*/
public static function create($method, $params)
{
$packet = new Notification($method, $params);
return $packet;
}
}
|