forked from gander/tweakphp-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
58 lines (46 loc) · 1.04 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
53
54
55
56
57
58
<?php
use TweakPHP\Client\Loader;
require __DIR__ . '/vendor/autoload.php';
$arguments = $argv;
if (count($arguments) < 3) {
echo 'Invalid arguments' . PHP_EOL;
exit(1);
}
function dd(...$args)
{
if (count($args) === 1) {
return $args[0];
}
return $args;
}
$loader = Loader::load($arguments[1]);
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);
}
echo $loader->execute(base64_decode($arguments[3])) . PHP_EOL;
break;
}