8000 fix: can send Json even if Flight is not started yet by pierresh · Pull Request #643 · flightphp/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: can send Json even if Flight is not started yet #643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pierresh
Copy link

With FlightPHP v2, we could send JSON easily, even if the method start() was not called yet.

Example:

require_once __DIR__ . '/vendor/autoload.php';

Flight::json("Hello");

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.

@pierresh
Copy link
Author

I see that one unit test fails, I will try to solve it.

@n0nag0n
Copy link
Collaborator
n0nag0n commented May 2, 2025

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;
});

@pierresh
Copy link
Author
pierresh commented May 2, 2025

Yes, I know, but I feel a bit strange that nothing is sent with Flight::json() in such situation. And I figured out that we have a few customized files which run outside of Flight::start() / Flight::route() for various reasons, thus changing from v2 to v3 is a breaking change.

But it is not a problem if you disagree, we will deal with them one by one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0