As of now controllers can return string, view or a response (we can't even return a model, which is shame). Since PHP doesn't support generic type, we don't know return type of controller just by looking at the doc block.
My proposal: if a controller returns something other than view or a string, we wrap it ourselves in a response and return that. Which will allow me to do something like this:
class IUser {
public $name;
public $email;
public $id
}
class Users extends Controller {
/**
* @return IUser
*/
public function getById() {
$user = new IUser();
$user->email = "some@thing.com";
$user->name = "Something";
$user->id = 3;
return $user;
}
}
In this case, we have a lot of information right there. Or anything actually, a model, a collection, anything should do.
In order to do this, we'll need to overwrite the handle method of application and should tackle the response type. I do think this handle method is way too long and it should really separate the handling of response separately in a method instead of writing a thousand lines of code (easy to test if we separated two different things to two different methods). Benefit of separating would include user being able to overwrite smaller pieces of component rather than having to overwrite the whole big method.