1 | <?php |
||
26 | class Node |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * Current version of PhuninNode |
||
31 | */ |
||
32 | const VERSION = '0.3.0-DEV'; |
||
33 | |||
34 | /** |
||
35 | * @var LoopInterface |
||
36 | */ |
||
37 | private $loop; |
||
38 | |||
39 | /** |
||
40 | * @var Socket |
||
41 | */ |
||
42 | private $socket; |
||
43 | |||
44 | /** |
||
45 | * @var Configuration |
||
46 | */ |
||
47 | private $configuration; |
||
48 | |||
49 | /** |
||
50 | * @var LoggerInterface |
||
51 | */ |
||
52 | private $logger; |
||
53 | |||
54 | /** |
||
55 | * Collection of Plugins in use (PluginInterface) |
||
56 | * |
||
57 | * @var \SplObjectStorage |
||
58 | */ |
||
59 | private $plugins; |
||
60 | |||
61 | /** |
||
62 | * Collection of connected clients (ConnectionContext) |
||
63 | * |
||
64 | * @var \SplObjectStorage |
||
65 | */ |
||
66 | private $connections; |
||
67 | |||
68 | private $commands; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | private $defaultConfiguration = [ |
||
74 | 'hostname' => 'HOSTNAME', |
||
75 | 'verbose' => false, |
||
76 | ]; |
||
77 | |||
78 | /** |
||
79 | * @param LoopInterface $loop |
||
80 | * @param Socket $socket The socket to bind on |
||
81 | * @param Configuration $configuration Node configuration |
||
82 | * @param LoggerInterface $logger Logger |
||
83 | */ |
||
84 | 42 | public function __construct( |
|
118 | |||
119 | /** |
||
120 | * Shutdown Node and the underlying socket |
||
121 | */ |
||
122 | 1 | public function shutdown() |
|
126 | |||
127 | /** |
||
128 | * @param Connection $conn |
||
129 | */ |
||
130 | 3 | public function onConnection(Connection $conn) |
|
134 | |||
135 | /** |
||
136 | * Detach connection from connection collection |
||
137 | * |
||
138 | * @param ConnectionContext $connection |
||
139 | */ |
||
140 | 2 | public function onClose(ConnectionContext $connection) |
|
144 | |||
145 | /** |
||
146 | * Attach a plugin |
||
147 | * |
||
148 | * @param PluginInterface $plugin |
||
149 | */ |
||
150 | 3 | public function addPlugin(PluginInterface $plugin) |
|
156 | |||
157 | /** |
||
158 | * Returns the plugins collection |
||
159 | * |
||
160 | * @return \SplObjectStorage |
||
161 | */ |
||
162 | 3 | public function getPlugins(): \SplObjectStorage |
|
166 | |||
167 | /** |
||
168 | * Return the connection collection |
||
169 | * |
||
170 | * @return \SplObjectStorage |
||
171 | */ |
||
172 | 4 | public function getConnections(): \SplObjectStorage |
|
176 | |||
177 | /** |
||
178 | * return the react |
||
179 | * |
||
180 | * @return LoopInterface |
||
181 | */ |
||
182 | 4 | public function getLoop(): LoopInterface |
|
186 | |||
187 | /** |
||
188 | * @return Configuration |
||
189 | */ |
||
190 | 5 | public function getConfiguration(): Configuration |
|
194 | |||
195 | /** |
||
196 | * @return CommandsCollection |
||
197 | */ |
||
198 | 1 | public function getCommands() |
|
202 | |||
203 | /** |
||
204 | * @return LoggerInterface |
||
205 | */ |
||
206 | 5 | public function getLogger(): LoggerInterface |
|
210 | |||
211 | /** |
||
212 | * Get a plugin by slug or return false when none can be found |
||
213 | * |
||
214 | * @param string $slug |
||
215 | * @return bool|PluginInterface |
||
216 | */ |
||
217 | 1 | public function getPlugin($slug) |
|
229 | } |
||
230 |