fix: can send Json even if Flight is not started yet#643
fix: can send Json even if Flight is not started yet#643pierresh wants to merge 1 commit intoflightphp:masterfrom pierresh:master
Conversation
|
I see that one unit test fails, I will try to solve it. |
|
So if you want you have a couple options. https://docs.flightphp.com/en/v3/learn/migrating-to-v3#output-buffering-behavior-3-5-0 You can turn on the old v2 behavior to have it do what you want. Or you can override the json method to do your bidding or create a new function altogether https://docs.flightphp.com/en/v3/learn/migrating-to-v3#output-buffering-behavior-3-5-0 // or 'jsonOutputNow'
Flight::map('json', function($data, $status, $flags) {
header('Content-Type: application/json');
http_response_code($status);
echo json_encode($data, $flags);
exit;
}); |
|
Yes, I know, but I feel a bit strange that nothing is sent with But it is not a problem if you disagree, we will deal with them one by one. |
|
Thanks @krmu for hitting me up on this. Forgot it was still open. I'm thinking through it and I still can't understand why you would want Flight just generate and echo the JSON in a given situation, when you can just create your own function to echo out JSON. The Flight::json() method sets status codes and headers that ultimately will never get sent to the browser. Maybe it is ill named and that's the confusion? I can see that people may think that this is how you use the framework to encode JSON when it should be something more like a |
|
Replaced with #657 |
|
You can now use |
With FlightPHP v2, we could send JSON easily, even if the method
start()was not called yet.Example:
Now, with v3, nothing happens unless the framework is started with
Flight::start()(and it seems requiring router defined, otherwise it returns a 404 error).This pull request aims to restore the simple behavior of Flight v2 to send a JSON.