-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
52 lines (42 loc) · 1.06 KB
/
index.php
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
<?php
use TweakPHP\Client\Cli;
use TweakPHP\Client\Loader;
require __DIR__.'/vendor/autoload.php';
$arguments = $argv;
if (count($arguments) < 3) {
echo 'Invalid arguments'.PHP_EOL;
exit(1);
}
$customLoader = Cli::getArgument('loader');
$loader = Loader::load($arguments[1], $customLoader);
if ($loader === null) {
echo 'Invalid path'.PHP_EOL;
exit(1);
}
$loader->init();
$supportedCommands = [
'info',
'execute',
];
if (! in_array($arguments[2], $supportedCommands)) {
echo 'Invalid command'.PHP_EOL;
exit(1);
}
switch ($arguments[2]) {
case 'info':
$info = json_encode([
'name' => $loader->name(),
'version' => $loader->version(),
'php_version' => phpversion(),
]);
echo $info.PHP_EOL;
break;
case 'execute':
if (count($arguments) < 4) {
echo 'Invalid arguments'.PHP_EOL;
exit(1);
}
$output = json_encode($loader->execute(base64_decode($arguments[3])));
echo 'TWEAKPHP_RESULT:'.$output.PHP_EOL;
break;
}