Closed jcbwlkr closed 11 years ago
Great idea to have a response handling system. This will definitely be added to Bullet, we just have to get the details right.
registerResponseHandler
, since Bullet already has the idea of "return a response", and "response types".callable
, or null
(no condition) to have it applied to every response.Response
object, not just the raw content, so the handler can test and modify more of the response than just the content. This would allow a broader range of requirements, like time-stamping every response or caching, etc.The updated code might look like this:
$app->registerResponseHandler(
function($response) {
return $response->content() instanceof Hal;
},
function($response) {
$response->contentType('application/hal+json');
return $response->content($response->content()->asJson());
}
);
It's slightly more verbose, but adds more power for the handler to be able to modify any part of the response it needs to, and removes a method argument that may limit us later down the road.
That makes sense. I have made the requested changes. I added a test to ensure that multiple handlers can be applied.
While I was in there I took a few liberties. I will gladly rewrite if you suggest it.
run
into _handleResponse
Good changes. I like it. :+1:
Great! I know it will be useful in my app and hopefully it will help someone else.
Add mechanism to allow for automatic conversion of response content and content type based on user defined test conditions.
I want to do this so I can do something like the following in my setup:
And in my routes I can do this:
The default behavior of converting Arrays to JSON has been preserved by a call to
registerContentConverter
in\Bullet\App::__construct