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 App::__invoke() method to enable custom integrations #236

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

clue
Copy link
Owner

@clue clue commented Aug 22, 2023

This changeset adds a new App::__invoke() method to make the App class callable and to enable custom integrations.

This method allows you to pass in a single HTTP request object that will be processed according to any registered routes and middleware and will return an HTTP response object as a result.

$app = new FrameworkX\App();
$app->get('/', fn() => React\Http\Message\Response::plaintext("Hello!\n"));

$request = new React\Http\Message\ServerRequest('GET', 'https://example.com/');
$response = $app($request);

assert($response instanceof Psr\Http\Message\ResponseInterface);
assert($response->getStatusCode() === 200);
assert($response->getBody()->getContents() === "Hello\n");

This is particularly useful for higher-level integration test suites and for custom integrations with other runtime environments like serverless functions or other frameworks. Otherwise, most applications would likely want to use the run() method to run the application and automatically accept incoming HTTP requests according to the PHP SAPI in use.

Builds on top of #235 and #224
Also refs #130 and #185

@clue clue added the new feature New feature or request label Aug 22, 2023
@SimonFrings SimonFrings merged commit 4da7203 into clue:main Aug 29, 2023
51 checks passed
@SimonFrings SimonFrings deleted the callable-app branch August 29, 2023 11:13
@SimonFrings SimonFrings added this to the v0.15.0 milestone Mar 5, 2024
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.

2 participants