41 private $optArgs = array();
47 private $needArgs = array();
53 private $hiddenArgs = array();
73 $this->
addHidden(
"api",
"api file to use");
74 $this->
addOption(
'userid',
"user system id to execute function - default is (admin)", array() , 1);
97 $this->hiddenArgs[] = array(
99 "def" => $argDefinition
101 return $this->action->getArgument($argName);
112 public function addNeeded($argName, $argDefinition, array $restriction = null)
114 $this->needArgs[] = array(
116 "def" => $argDefinition,
117 "restriction" => $restriction
119 return $this->action->getArgument($argName);
131 public function addOption($argName, $argDefinition, array $restriction = null, $default = null)
133 $this->optArgs[] = array(
135 "def" => $argDefinition,
136 "default" => $default,
137 "restriction" => $restriction
139 return $this->action->getArgument($argName, $default);
148 private function getArgumentText(array $args)
151 foreach ($args as
$arg) {
153 if ($arg[
"restriction"]) {
154 $res =
' [' . implode(
'|', $arg[
"restriction"]) .
']';
157 if ($arg[
"default"] !== null) {
158 $default = sprintf(
", default is '%s'", $arg[
"default"]);
160 $usage.= sprintf(
"\t--%s=<%s>%s%s\n", $arg[
"name"], $arg[
"def"], $res, $default);
173 $usage.= $this->getArgumentText($this->needArgs);
175 $usage.= $this->getArgumentText($this->optArgs);
188 if ($error !=
'') $error.=
"\n";
192 $error.=
'<pre>' . htmlspecialchars(
$usage) .
'</pre>';
196 $this->action->exitError($error);
206 foreach ($this->hiddenArgs as $v) {
207 $keys[] = $v[
"name"];
230 public function verify($useException =
false)
232 foreach ($this->needArgs as $arg) {
233 $value = $this->action->getArgument($arg[
"name"]);
235 $error = sprintf(
"argument '%s' expected\n", $arg[
"name"]);
243 $allArgs = array_merge($this->needArgs, $this->optArgs);
246 foreach ($allArgs as $arg) {
247 $value = $this->action->getArgument($arg[
"name"], null);
248 if (
$value !== null && $arg[
"restriction"]) {
249 if (!in_array(
$value, $arg[
"restriction"])) {
250 $error = sprintf(
"argument '%s' must be one of these values : %s\n", $arg[
"name"], implode(
", ", $arg[
"restriction"]));
258 $argsKey[] = $arg[
"name"];
261 foreach (
$_GET as $k => $v) {
262 if (!in_array($k, $argsKey)) {
263 $error = sprintf(
"argument '%s' is not defined\n", $k);