There are possible advantages, yes - but you'd have to implement it correctly.
For example:
PHP Code:
Class RequestData{
protected $Get, $Post, $Cookie, $Session, $Files;
function __Construct(){
$this->Get = $_GET;
$this->Post = $_POST;
$this->Cookie = $_COOKIE;
$this->Session = $_SESSION;
$this->Files = $_FILES;
}
//etc
}
This isn't the right way to do it, as all instances contain the same thing. However, you can do the following:
PHP Code:
Class RequestData{
protected $Get, $Post, $Cookie, $Session, $Files;
function __Construct(array $Get = array(), array $Post = array(), array $Cookie = array(), array $Session = array(), array $Files = array()){
$this->Get = $Get;
$this->Post = $Post;
$this->Cookie = $Cookie;
$this->Session = $Session;
$this->Files = $Files;
}
protected function getValue($Key, $Array){
return Array_Key_Exists($Key, $this->$Array) ? $this->$Array[$Key] : false;
}
public function Get($Key){
return $this->getValue($Key, 'Get');
}
public function Post($Key){
return $this->getValue($Key, 'Post');
}
//etc
}
$RequestData = new RequestData($_GET, $_POST, $_COOKIE, $_SESSION, $_FILES);
This way you can simulate a request by instantiating this RequestData class with custom data and pass it to an object to parse as a real request - allowing you to perform many different tasks (through pseudo-requests) on a single request.
Bookmarks