-
Notifications
You must be signed in to change notification settings - Fork 3.4k
PSR 15 #12907
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
Conversation
…f callables. It's resolver also wraps callables with DoublePassMiddleware decorator for compatibility with old callable middlewares.
*/ | ||
protected $callables = []; | ||
protected $middlewares = []; |
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.
I learned this in my PR cakephp/app#630:
Plural of middleware is middleware.
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.
I think it's acceptable to ignore grammatical rules for a variable name to make it apparent that this is a list of multiple middleware.
Also there are some source which state that in technical context the plural form is middlewares
.
BC issue can occur if any existing double pass middleware manipulates the response instance before passing it to |
Function in |
Hmm... that sounds worth trying. |
src/Http/BaseApplication.php
Outdated
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function __invoke( | ||
public function process( |
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.
While not likely it is possible that userland applications have overridden __invoke(). We might want to have a shim __invoke
method that calls process()
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.
IMO it would be acceptable to ask users to just update their application class for a new major release, for such a rarely required modification.
All tests pass now. I can start cleaning things up and updating the core middlewares to PSR 15 standard upon approval. @garas I tried your idea of checking for prematurely modified response in |
Codecov Report
@@ Coverage Diff @@
## 4.x #12907 +/- ##
============================================
+ Coverage 93.15% 93.16% +<.01%
- Complexity 13202 13208 +6
============================================
Files 468 470 +2
Lines 32801 32810 +9
============================================
+ Hits 30556 30566 +10
+ Misses 2245 2244 -1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## 4.x #12907 +/- ##
============================================
- Coverage 93.14% 93.14% -0.01%
- Complexity 13203 13212 +9
============================================
Files 468 470 +2
Lines 32787 32809 +22
============================================
+ Hits 30541 30559 +18
- Misses 2246 2250 +4
Continue to review full report at Codecov.
|
@markstory Stickler needs a smack 🙂. phpcs build is passing on travis and locally too for me. |
@ADmad Stickler only has the 'old' CakePHP code standard installed. I've not figured a clever way to have both versions installed. |
…te a response. HttpAllicationInterface now extends RequestHanlderInterface instead of MiddlewareInterface.
dfc1d07
to
b4414cb
Compare
All changes done as per feedback. This is ready for final review. |
} | ||
|
||
return $response; | ||
$this->logException($request, $exception); |
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.
The empty catch block is a bit odd. Should this go in the catch?
src/Http/Runner.php
Outdated
} | ||
|
||
// End of the queue | ||
return $response; | ||
return (new Response())->withStatus(500); |
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 could have a body that makes it easier for the user to know what went wrong. I don't see this as an error that should happen much in production so it could contain context on how to fix the problem.
tests/TestCase/Http/RunnerTest.php
Outdated
* | ||
* @return void | ||
*/ | ||
public function testRunResponseReplace() | ||
{ | ||
$this->markTestSkipped( | ||
'Skip until we figure out a way to test for premature response modification in DoublePassMiddleware.' |
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.
Any idea on what to do here?
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.
I couldn't find a way to check and warn dev for this, so I think the test should be just dropped. The middleware example in manual does have a comment stating that response should be modified after calling $next.
@markstory Updates done as per your feedback. |
@markstory I cleaned up |
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.
Looks good to me.
This implements PSR 15 support while maintaining the ability to use existing invokable/callable middlewares.
A notable change is you can no longer pass a response instance to
Server::run()
(though I am not sure it has much practical use). If we want to retain the ability to pass a custom response instance to app than we can do by adding a new argument toBaseApplication
's constructor.P.S. I haven't added/updated the docblocks so please avoid commenting on that for now.