Skip to content
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

Add fiber compatibility mode for PHP < 8.1 #128

Merged
merged 1 commit into from
Mar 7, 2022

Conversation

clue
Copy link
Owner

@clue clue commented Mar 4, 2022

This changeset adds a limited fiber compatibility mode for PHP < 8.1. This means you can now simply use await() in your controller code on any supported PHP version without having to wrap anything in any explicit async calls anymore. This makes building and consuming async APIs easier than ever before.

$app->get('/book/{isbn}', function (Psr\Http\Message\ServerRequestInterface $request) use ($db) {
    $isbn = $request->getAttribute('isbn');
    $result = await($db->query(
        'SELECT title FROM book WHERE isbn = ?',
        [$isbn]
    ));

    assert($result instanceof React\MySQL\QueryResult);
    $data = $result->resultRows[0]['title'];

    return React\Http\Message\Response::plaintext(
        $data
    );
});

Builds on top of #116, #117, and #118

@clue clue added the new feature New feature or request label Mar 4, 2022
@clue clue requested a review from SimonFrings March 4, 2022 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants