1 | <?php |
||
23 | class CLIRunner implements CLIRunnerInterface{ |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | const COMMANDS = [ |
||
29 | // local |
||
30 | 'keypair' => 'getKeypair', |
||
31 | 'hash_email' => 'hashEmail', |
||
32 | 'hash_phone' => 'hashPhone', |
||
33 | 'encrypt' => 'encryptFile', |
||
34 | 'decrypt' => 'decryptFile', |
||
35 | // network |
||
36 | 'credits' => 'checkCredits', |
||
37 | 'check' => 'checkCapabilities', |
||
38 | 'email2id' => 'getIdByEmail', |
||
39 | 'phone2id' => 'getIdByPhone', |
||
40 | 'id2pubkey' => 'getPubkeyById', |
||
41 | 'send' => 'sendMessage', |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * @var \chillerlan\Threema\Crypto\CryptoInterface |
||
46 | */ |
||
47 | protected $cryptoInterface; |
||
48 | |||
49 | /** |
||
50 | * @var \chillerlan\Threema\GatewayOptions |
||
51 | */ |
||
52 | protected $gatewayOptions; |
||
53 | |||
54 | /** |
||
55 | * @var \chillerlan\Threema\Gateway |
||
56 | */ |
||
57 | protected $threemaGateway; |
||
58 | |||
59 | /** |
||
60 | * @var \ReflectionClass |
||
61 | */ |
||
62 | protected $reflection; |
||
63 | |||
64 | /** |
||
65 | * @var array[\ReflectionMethod] |
||
66 | */ |
||
67 | private $CLIRunnerInterfaceMap; |
||
68 | |||
69 | /** |
||
70 | * CLIRunner constructor. |
||
71 | * |
||
72 | * @param \chillerlan\Threema\Crypto\CryptoInterface $cryptoInterface |
||
73 | * @param \chillerlan\Threema\GatewayOptions $gatewayOptions |
||
74 | */ |
||
75 | public function __construct(CryptoInterface $cryptoInterface, GatewayOptions $gatewayOptions){ |
||
85 | |||
86 | /** |
||
87 | * @param array $arguments $_SERVER['argc'] |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | public function run(array $arguments):string{ |
||
110 | |||
111 | /** |
||
112 | * output a string, wrap at 100 chars |
||
113 | * |
||
114 | * @param string $string string to output |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | protected function log2cli(string $string):string{ |
||
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | * @codeCoverageIgnore |
||
125 | */ |
||
126 | protected function readStdIn(){ |
||
141 | |||
142 | /** |
||
143 | * @param array $params |
||
144 | * |
||
145 | * @return \stdClass |
||
146 | */ |
||
147 | protected function parseDocBlock(array $params):stdClass{ |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | public function help():string{ |
||
205 | |||
206 | /** |
||
207 | * @param string $path |
||
208 | * @param string $data |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | protected function writeFile(string $path, string $data):string{ |
||
221 | |||
222 | /** |
||
223 | * @inheritdoc |
||
224 | */ |
||
225 | public function getKeypair(string $privateKeyFile = null, string $publicKeyFile = null):string{ |
||
232 | |||
233 | /** |
||
234 | * @inheritdoc |
||
235 | */ |
||
236 | public function hashEmail(string $email):string{ |
||
239 | |||
240 | /** |
||
241 | * @inheritdoc |
||
242 | */ |
||
243 | public function hashPhone(string $phoneNo):string{ |
||
246 | |||
247 | /** |
||
248 | * @inheritdoc |
||
249 | */ |
||
250 | public function checkCredits():string{ |
||
253 | |||
254 | /** |
||
255 | * @inheritdoc |
||
256 | */ |
||
257 | public function checkCapabilities(string $threemaID):string{ |
||
260 | |||
261 | /** |
||
262 | * @inheritdoc |
||
263 | */ |
||
264 | public function getIdByEmail(string $email):string{ |
||
267 | |||
268 | /** |
||
269 | * @inheritdoc |
||
270 | */ |
||
271 | public function getIdByPhone(string $phoneNo):string{ |
||
274 | |||
275 | /** |
||
276 | * @inheritdoc |
||
277 | */ |
||
278 | public function getPubkeyById(string $threemaID):string{ |
||
281 | |||
282 | /** |
||
283 | * @inheritdoc |
||
284 | */ |
||
285 | public function encryptFile(string $privateKey, string $publicKey, string $plaintextFile, string $encryptedFile):string{ |
||
289 | |||
290 | /** |
||
291 | * @inheritdoc |
||
292 | */ |
||
293 | public function decryptFile(string $privateKey, string $publicKey, string $encryptedFile, string $decryptedFile):string{ |
||
297 | |||
298 | /** |
||
299 | * @inheritdoc |
||
300 | */ |
||
301 | public function sendMessage(string $toThreemaID, string $message):string{ |
||
304 | } |
||
305 |