-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjsonrpc-cli
More file actions
executable file
·73 lines (60 loc) · 1.59 KB
/
jsonrpc-cli
File metadata and controls
executable file
·73 lines (60 loc) · 1.59 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env php
<?php
/**
* Entry point for jsonrpc-cli.
*
* Code in this file is related to interacting with the shell.
*/
// Let's be strict about things.
require_once __DIR__ . '/vendor/autoload.php';
\strictmode\initializer::init();
use App\Utils\MyLogger;
use App\AppCore;
use App\Utils\Report;
use App\Utils\Util;
/**
* Our main function. It performs top-level exception handling.
*/
function main()
{
// why limit ourselves? ;-)
ini_set('memory_limit', -1 );
try
{
// CLI Parameters processing
$orig_params = Util::getCliParams();
list( $params, $success ) = Util::processCliParams();
if( $success != 0 )
{
return $success;
}
// Creates AppCore object
$app = new AppCore($params);
$response = $app->request();
// Prints result
echo "\n";
Report::printResults($params, $response);
return 0;
}
catch(Exception $e)
{
if(@$params) {
$format = @$params['format'] ?: 'printr';
$err = MyLogger::getInstance()->exception_to_array( $e );
$err = (count($err) == 1) ? $err[0] : $err;
Report::printResults($params, $err);
}
else {
fprintf( STDOUT, "\n" . $e->getMessage() . "\n\n" );
}
// echo str_replace('\n#', "\n#", $json);
/*
// print validation errors to stdout.
if( $e->getCode() == 2 ) {
fprintf( STDOUT, $e->getMessage() . "\n\n" );
}
*/
return $e->getCode() ?: 1;
}
}
exit(main());