owncloud/appframework — pull request #4 by tanghus (2013-03-27 02:01:25+00:00)
Title: Request class suggestion

I had a look at the Request class, and found it not really intuitive to use.

Here's a suggestion that uses some of the good parts in PHP - yes, there are some ;)

Instead of instantiating it with a fairly long list of parameters, it takes only one array argument, which is an associative array. For basic use without URL parameters it can be instantiated without any argument.

I decided to make it immutable, because it is imho bad to alter the variables, and I don't think app developers should set session variables or cookies. That is of course only one opinion, and can be changed.

The different ways of accessing request variables can be seen in the [unit tests](https://github.com/owncloud/appframework/blob/request_class_suggestion/tests/http/RequestTest.php)

Access can be done either as an array or with PHPs "magic accessors".

`$request->nickname;`, `$request->{'nickname'};` and `$request['nickname']` does the same, namely get the `nickname` variable from the combined `params`, `GET`, `POST` and `urlParams`.

If you want to access specifically from one of the arrays you can use `$request->post['nickname'];`, `$request->env['PATH'];` and so on. `$request->method` returns the request method.

For getting a variable with a default value use e.g. `$request->getVar('post', 'nickname', 'Joey');`