-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.STCLI.php
90 lines (67 loc) · 1.86 KB
/
class.STCLI.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Mainclass for Steroid CLI
* @package steroid\cli
*/
require_once __DIR__ . "/class.ST.php";
require_once STROOT . '/util/class.ClassFinder.php';
require_once STROOT . '/clihandler/class.CLIHandler.php';
class STCLI extends ST {
/** @var string */
protected $called;
/** @var string */
protected $command;
/** @var string[] */
protected $params;
/**
*
* @param IStorage $storage
* @param string[] $args
*/
public function __construct( Config $conf, IRBStorage $storage, array $args ) {
parent::__construct($conf, $storage);
$this->called = array_shift( $args );
$this->parseGlobalParams( $args );
$this->command = array_shift( $args );
$this->params = $args;
}
final private function parseGlobalParams( array &$args ) {
while( $args ) {
switch ( $args[0] ) {
// some php versions have faulty gc implementations
case '--gc-disable':
gc_disable();
array_shift($args);
echo "gc_disabe()\n";
break;
case '--mem-limit':
array_shift($args);
if ( is_numeric($args[0]) ) {
$memLimit = array_shift($args);
ini_set('memory_limit', $memLimit);
echo "ini_set('memory_limit', " . $memLimit . ")\n";
}
break;
default:
return;
}
}
}
/**
* @return int
*/
public function __invoke() {
require_once STROOT . '/cli/clidefines.php';
try {
$cliHandler = CLIHandler::getCLIHandler( $this->storage, $this->command );
$params = CLIHandler::parseParams( $this->params );
$returnCode = $cliHandler->performCommand( $this->called, $this->command, $params );
} catch( Exception $e ) { // catch other exceptions which may be unknown to us
Log::write( $e );
$returnCode = EXIT_FAILURE;
}
return $returnCode;
}
}
class UnknownInstallTaskException extends Exception {}
class InvalidCLIHandlerException extends Exception {}