-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Added App::process() to expose Request -> Response functionality #1688
Conversation
@@ -297,13 +297,39 @@ public function run($silent = false) | |||
$request = $this->container->get('request'); | |||
$response = $this->container->get('response'); | |||
|
|||
$response = $this->process($request, $response); | |||
|
|||
$response = $this->finalize($response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This:
$response = $this->finalize($response);
should be on process(), shouldn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot!
I don't see the problem you are solving with this PR. Is there something that __invoke doesn't do that you need?
|
When using directly __invoke, you are ignoring the app level middlewares. I think this is the only problem. |
I think we should fix that... |
$request = Request::createFromGlobals();
$response = $app($request, $response);
$app->send($response); Was the same as doing: $app->run(); Then that would solve the problem. (Edit) - But that sort of change couldn't be made until 4.x because it would break B/C |
@AndrewCarterUK there is 1 other way to do this.
https://github.com/slimphp/Slim/blob/3.x/tests/AppTest.php#L1558-L1592 |
@geggleto That only works if you've patched the container or want the request to be created from global variables. In my project the request is received from a FastCGI connection. (edit to clarify: That's not PHP-FPM, the application runs as its own FastCGI daemon) |
Looks good to me and maybe is that start of removing request and response from the container. |
The same problem is for creating WebTest class that mocks Slim, creates a request and checks response object. For now I'm using __invoke which works, because I don't have any middleware yet. |
@akrabat is there an issue for that? |
@stivni its a 4.0 thing ;) |
The Problem
It's currently very difficult to give the application a request and retrieve a response. To have a request that isn't created from the PHP super globals you need to patch the container.
A project of mine (PHPFastCGI) has struggled to provide a clean adapter to the Slim framework for this reason.
The Solution
Split
App::run()
into two methods by creatingApp::process()
. The latter acts as a simple map from request to response.Downsides
The are two that I can think of:
App:process()
andApp::__invoke()
. Both have the same signature and do similar things, but ultimately at a different level.Questions
Assuming that people think this is a good idea:
App::run()
now coversApp:process()
. I'm not adverse to adding unit tests, I just thought it was worth asking here what people think they should look like rather than just adding something pointless for the sake of it.Interested to hear thoughts :)