10 defined(
'JPATH_PLATFORM') or die;
36 public $args = array();
46 public function __construct(array $source = null, array $options = array())
48 if (isset($options[
'filter']))
50 $this->filter = $options[
'filter'];
58 $this->parseArguments();
61 $this->options = $options;
71 public function serialize()
74 $this->loadAllInputs();
77 $inputs = $this->inputs;
78 unset($inputs[
'env']);
79 unset($inputs[
'server']);
82 return serialize(array($this->executable, $this->args, $this->options, $this->data, $inputs));
94 public function unserialize($input)
97 list($this->executable, $this->args, $this->options, $this->data, $this->inputs) = unserialize($input);
100 if (isset($this->options[
'filter']))
102 $this->filter = $this->options[
'filter'];
119 protected function parseArguments()
121 $argv = $_SERVER[
'argv'];
123 $this->executable = array_shift($argv);
127 for ($i = 0, $j = count($argv); $i < $j; $i++)
132 if (substr($arg, 0, 2) ===
'--')
134 $eqPos = strpos($arg,
'=');
137 if ($eqPos ===
false)
139 $key = substr($arg, 2);
142 if ($i + 1 < $j && $argv[$i + 1][0] !==
'-')
144 $value = $argv[$i + 1];
149 $value = isset($out[$key]) ? $out[$key] :
true;
158 $key = substr($arg, 2, $eqPos - 2);
159 $value = substr($arg, $eqPos + 1);
163 elseif (substr($arg, 0, 1) ===
'-')
167 if (substr($arg, 2, 1) ===
'=')
169 $key = substr($arg, 1, 1);
170 $value = substr($arg, 3);
176 $chars = str_split(substr($arg, 1));
178 foreach ($chars as $char)
181 $value = isset($out[$key]) ? $out[$key] :
true;
186 if ((count($chars) === 1) && ($i + 1 < $j) && ($argv[$i + 1][0] !==
'-'))
188 $out[$key] = $argv[$i + 1];
196 $this->args[] = $arg;