10 defined(
'JPATH_PLATFORM') or die;
41 class
JInput implements Serializable, Countable
49 protected $options = array();
57 protected $filter = null;
65 protected $data = array();
73 protected $inputs = array();
83 public function __construct($source = null, array $options = array())
85 if (isset($options[
'filter']))
87 $this->filter = $options[
'filter'];
96 $this->data = &$_REQUEST;
100 $this->data = $source;
104 $this->options = $options;
116 public function __get($name)
118 if (isset($this->inputs[$name]))
120 return $this->inputs[$name];
123 $className =
'JInput' . ucfirst($name);
125 if (class_exists($className))
127 $this->inputs[$name] =
new $className(null, $this->options);
129 return $this->inputs[$name];
132 $superGlobal =
'_' . strtoupper($name);
136 $this->inputs[$name] =
new JInput(
$GLOBALS[$superGlobal], $this->options);
138 return $this->inputs[$name];
152 public function count()
154 return count($this->data);
168 public function get($name, $default = null, $filter =
'cmd')
170 if (isset($this->data[$name]))
172 return $this->filter->clean($this->data[$name], $filter);
190 public function getArray(array $vars = array(), $datasource = null)
192 if (empty($vars) && is_null($datasource))
199 foreach ($vars as $k => $v)
203 if (is_null($datasource))
205 $results[$k] = $this->getArray($v, $this->
get($k, null,
'array'));
209 $results[$k] = $this->getArray($v, $datasource[$k]);
214 if (is_null($datasource))
216 $results[$k] = $this->
get($k, null, $v);
218 elseif (isset($datasource[$k]))
220 $results[$k] = $this->filter->clean($datasource[$k], $v);
224 $results[$k] = $this->filter->clean(null, $v);
242 public function set($name, $value)
244 $this->data[$name] = $value;
257 public function def($name, $value)
259 if (isset($this->data[$name]))
264 $this->data[$name] = $value;
277 public function __call($name, $arguments)
279 if (substr($name, 0, 3) ==
'get')
281 $filter = substr($name, 3);
285 if (isset($arguments[1]))
287 $default = $arguments[1];
290 return $this->
get($arguments[0], $default, $filter);
301 public function getMethod()
303 $method = strtoupper($_SERVER[
'REQUEST_METHOD']);
315 public function serialize()
318 $this->loadAllInputs();
321 $inputs = $this->inputs;
322 unset($inputs[
'env']);
323 unset($inputs[
'server']);
326 return serialize(array($this->options, $this->data, $inputs));
338 public function unserialize($input)
341 list($this->options, $this->data, $this->inputs) = unserialize($input);
344 if (isset($this->options[
'filter']))
346 $this->filter = $this->options[
'filter'];
361 protected function loadAllInputs()
363 static $loaded =
false;
368 foreach (
$GLOBALS as $global => $data)
371 if (strpos($global,
'_') === 0)
374 $global = strtolower($global);
375 $global = substr($global, 1);