1 | <?php |
||
25 | class CLIRunner implements CLIRunnerInterface{ |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | const COMMANDS = [ |
||
31 | // local |
||
32 | 'keypair' => 'getKeypair', |
||
33 | 'hash_email' => 'hashEmail', |
||
34 | 'hash_phone' => 'hashPhone', |
||
35 | 'encrypt' => 'encryptFile', |
||
36 | 'decrypt' => 'decryptFile', |
||
37 | // network |
||
38 | 'credits' => 'checkCredits', |
||
39 | 'check' => 'checkCapabilities', |
||
40 | 'email2id' => 'getIdByEmail', |
||
41 | 'phone2id' => 'getIdByPhone', |
||
42 | 'id2pubkey' => 'getPubkeyById', |
||
43 | 'send' => 'sendMessage', |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * @var \chillerlan\Threema\Crypto\CryptoInterface |
||
48 | */ |
||
49 | protected $cryptoInterface; |
||
50 | |||
51 | /** |
||
52 | * @var \chillerlan\Threema\Endpoint\EndpointInterface |
||
53 | */ |
||
54 | protected $endpointInterface; |
||
55 | |||
56 | /** |
||
57 | * @var \ReflectionClass |
||
58 | */ |
||
59 | protected $reflection; |
||
60 | |||
61 | /** |
||
62 | * @var array[\ReflectionMethod] |
||
63 | */ |
||
64 | protected $CLIRunnerInterfaceMap; |
||
65 | |||
66 | /** |
||
67 | * Gateway constructor. |
||
68 | * |
||
69 | * @param \chillerlan\Threema\Endpoint\EndpointInterface $endpointInterface |
||
70 | * @param \chillerlan\Threema\Crypto\CryptoInterface $cryptoInterface |
||
71 | */ |
||
72 | public function __construct(EndpointInterface $endpointInterface, CryptoInterface $cryptoInterface){ |
||
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | protected function mapMethods(){ |
||
88 | |||
89 | /** |
||
90 | * @param array $arguments $_SERVER['argc'] |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | public function run(array $arguments):string{ |
||
113 | |||
114 | /** |
||
115 | * output a string, wrap at 100 chars |
||
116 | * |
||
117 | * @param string $string string to output |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | private function log2cli(string $string):string{ |
||
124 | |||
125 | /** @noinspection PhpUnusedPrivateMethodInspection |
||
126 | * |
||
127 | * @return string |
||
128 | * @codeCoverageIgnore |
||
129 | */ |
||
130 | private function readStdIn(){ |
||
145 | |||
146 | /** |
||
147 | * @param array $params |
||
148 | * |
||
149 | * @return \stdClass |
||
150 | */ |
||
151 | private function parseDocBlock(array $params):stdClass{ |
||
173 | |||
174 | /** |
||
175 | * @param array $tag |
||
176 | * @param \stdClass &$out |
||
177 | */ |
||
178 | private function parseDocTag(array $tag, stdClass &$out){ |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | public function help():string{ |
||
218 | |||
219 | /** |
||
220 | * @param string $path |
||
221 | * @param string $data |
||
222 | * |
||
223 | * @return string |
||
224 | */ |
||
225 | protected function writeFile(string $path, string $data):string{ |
||
234 | |||
235 | /** |
||
236 | * @inheritdoc |
||
237 | */ |
||
238 | public function getKeypair(string $privateKeyFile = null, string $publicKeyFile = null):string{ |
||
245 | |||
246 | /** |
||
247 | * @inheritdoc |
||
248 | */ |
||
249 | public function hashEmail(string $email):string{ |
||
252 | |||
253 | /** |
||
254 | * @inheritdoc |
||
255 | */ |
||
256 | public function hashPhone(string $phoneNo):string{ |
||
259 | |||
260 | /** |
||
261 | * @inheritdoc |
||
262 | */ |
||
263 | public function checkCredits():string{ |
||
266 | |||
267 | /** |
||
268 | * @inheritdoc |
||
269 | */ |
||
270 | public function checkCapabilities(string $threemaID):string{ |
||
273 | |||
274 | /** |
||
275 | * @inheritdoc |
||
276 | */ |
||
277 | public function getIdByEmail(string $email):string{ |
||
280 | |||
281 | /** |
||
282 | * @inheritdoc |
||
283 | */ |
||
284 | public function getIdByPhone(string $phoneNo):string{ |
||
287 | |||
288 | /** |
||
289 | * @inheritdoc |
||
290 | */ |
||
291 | public function getPubkeyById(string $threemaID):string{ |
||
294 | |||
295 | /** |
||
296 | * @inheritdoc |
||
297 | */ |
||
298 | public function encryptFile(string $privateKey, string $publicKey, string $plaintextFile, string $encryptedFile):string{ |
||
302 | |||
303 | /** |
||
304 | * @inheritdoc |
||
305 | */ |
||
306 | public function decryptFile(string $privateKey, string $publicKey, string $encryptedFile, string $decryptedFile):string{ |
||
310 | |||
311 | /** |
||
312 | * @inheritdoc |
||
313 | */ |
||
314 | public function sendMessage(string $toThreemaID, string $message):string{ |
||
317 | } |
||
318 |