|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WyriHaximus\React\ChildProcess\Messenger\Messages; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Inflector\Inflector; |
|
6
|
|
|
|
|
7
|
|
|
class Factory |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param string $line |
|
11
|
|
|
* |
|
12
|
|
|
* @throws \Exception |
|
13
|
|
|
* @return mixed |
|
14
|
|
|
* |
|
15
|
|
|
*/ |
|
16
|
12 |
|
public static function fromLine($line, array $lineOptions) |
|
17
|
|
|
{ |
|
18
|
12 |
|
$line = json_decode($line, true); |
|
19
|
12 |
|
$method = Inflector::camelize($line['type']) . 'FromLine'; |
|
20
|
12 |
|
if (method_exists(get_class(new static()), $method) && $method !== 'FromLine') { |
|
21
|
11 |
|
return static::$method($line, $lineOptions); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
1 |
|
throw new \Exception('Unknown message type: ' . $line['type']); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param array $payload |
|
29
|
|
|
* |
|
30
|
|
|
* @return Message |
|
31
|
|
|
*/ |
|
32
|
3 |
|
public static function message(array $payload = []) |
|
33
|
|
|
{ |
|
34
|
3 |
|
return new Message(new Payload($payload)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param array $payload |
|
39
|
|
|
* |
|
40
|
|
|
* @return Error |
|
41
|
|
|
*/ |
|
42
|
3 |
|
public static function error(array $payload = []) |
|
43
|
|
|
{ |
|
44
|
3 |
|
return new Error(new Payload($payload)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $target |
|
49
|
|
|
* @param array $payload |
|
50
|
|
|
* @param mixed $uniqid |
|
51
|
|
|
* |
|
52
|
|
|
* @return Rpc |
|
53
|
|
|
*/ |
|
54
|
6 |
|
public static function rpc($target, array $payload = [], $uniqid = '') |
|
55
|
|
|
{ |
|
56
|
6 |
|
return new Rpc($target, new Payload($payload), $uniqid); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $target |
|
|
|
|
|
|
61
|
|
|
* @param array $payload |
|
62
|
|
|
* @param mixed $uniqid |
|
63
|
|
|
* |
|
64
|
|
|
* @return Rpc |
|
65
|
|
|
*/ |
|
66
|
3 |
|
public static function rpcError($uniqid, array $payload = []) |
|
67
|
|
|
{ |
|
68
|
3 |
|
return new RpcError($uniqid, new Payload($payload)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $uniqid |
|
73
|
|
|
* @param array $payload |
|
74
|
|
|
* |
|
75
|
|
|
* @return RpcSuccess |
|
76
|
|
|
*/ |
|
77
|
3 |
|
public static function rpcSuccess($uniqid, array $payload = []) |
|
78
|
|
|
{ |
|
79
|
3 |
|
return new RpcSuccess($uniqid, new Payload($payload)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $uniqid |
|
84
|
|
|
* @param array $payload |
|
85
|
|
|
* |
|
86
|
|
|
* @return RpcSuccess |
|
87
|
|
|
*/ |
|
88
|
2 |
|
public static function rpcNotify($uniqid, array $payload = []) |
|
89
|
|
|
{ |
|
90
|
2 |
|
return new RpcNotify($uniqid, new Payload($payload)); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param string $line |
|
95
|
|
|
* @param array $lineOptions |
|
96
|
|
|
* |
|
97
|
|
|
* @throws \Exception |
|
98
|
|
|
* @return mixed |
|
99
|
|
|
* |
|
100
|
|
|
*/ |
|
101
|
1 |
|
protected static function secureFromLine($line, array $lineOptions) |
|
102
|
|
|
{ |
|
103
|
1 |
|
return SecureLine::fromLine($line, $lineOptions); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param array $line |
|
108
|
|
|
* |
|
109
|
|
|
* @return Message |
|
110
|
|
|
*/ |
|
111
|
2 |
|
protected static function messageFromLine(array $line) |
|
112
|
|
|
{ |
|
113
|
2 |
|
return static::message($line['payload']); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param array $line |
|
118
|
|
|
* |
|
119
|
|
|
* @return Error |
|
120
|
|
|
*/ |
|
121
|
1 |
|
protected static function errorFromLine(array $line) |
|
122
|
|
|
{ |
|
123
|
1 |
|
return static::error($line['payload']); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param array $line |
|
128
|
|
|
* |
|
129
|
|
|
* @return Rpc |
|
130
|
|
|
*/ |
|
131
|
4 |
|
protected static function rpcFromLine(array $line) |
|
132
|
|
|
{ |
|
133
|
4 |
|
return static::rpc($line['target'], $line['payload'], $line['uniqid']); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param array $line |
|
138
|
|
|
* |
|
139
|
|
|
* @return Rpc |
|
140
|
|
|
*/ |
|
141
|
1 |
|
protected static function rpcErrorFromLine(array $line) |
|
142
|
|
|
{ |
|
143
|
1 |
|
return static::rpcError($line['uniqid'], $line['payload']); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param array $line |
|
148
|
|
|
* @return RpcSuccess |
|
149
|
|
|
*/ |
|
150
|
2 |
|
protected static function rpcSuccessFromLine(array $line) |
|
151
|
|
|
{ |
|
152
|
2 |
|
return static::rpcSuccess($line['uniqid'], $line['payload']); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param array $line |
|
157
|
|
|
* @return RpcSuccess |
|
158
|
|
|
*/ |
|
159
|
1 |
|
protected static function rpcNotifyFromLine(array $line) |
|
160
|
|
|
{ |
|
161
|
1 |
|
return static::rpcNotify($line['uniqid'], $line['payload']); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.