I'm new to OOP PHP and I created a simple input helper class. And was wondering if it's good? Are my dependencies good?
Also the reason I'm not throwing an exception with the get method is that I will mainly use this class for form validation purposes.
I'll take any suggestion for improvement!
class Input {
private $_get,
$_post;
public function __construct(Array $get, Array $post) {
$this->_get = $get;
$this->_post = $post;
}
public function exists($type = 'POST') {
switch($type) {
case 'POST':
return (!empty($this->_post)) ? true : false;
break;
case 'GET':
return (!empty($this->_get)) ? true : false;
break;
default:
return false;
break;
}
}
public function get($input, $source = 'POST') {
if($source == 'POST' && isset($this->_post[$input])) {
return $this->_post[$input];
} elseif($source == 'GET' && isset($this->_get[$input])) {
return $this->_get[$input];
}
return false;
}
}
I figured I could made my code shorter:
class Input {
private $_source;
public function __construct(Array $source) {
$this->_source = $source;
}
public function exists() {
return !empty($this->_source);
}
public function get($input) {
return (isset($this->_source[$input])) ? $this->_source[$input] : false;
}
}