-
Notifications
You must be signed in to change notification settings - Fork 32
Conversation
|
||
$result = $listener($event); | ||
$this->assertEquals($method, $request->getMethod()); | ||
|
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.
Please remove empty line above.
if (!in_array($method, $this->methods)) { | ||
return new ApiProblemResponse(new ApiProblem( | ||
400, | ||
'unrecognized method in X-HTTP-Method-Ovverride header' |
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.
Please change to uppercase U
in unrecognized
word
PR for this issue: zfcampus/zf-apigility#175 (comment) I think enabling this listener should be optional, feels not good to connect such a feature by default to the application so I connected the listener depending on a Not sure exactly on what is a valid priority value for this listener. I would say as early as possible, currently set to |
if (! in_array($method, $this->methods)) { | ||
return new ApiProblemResponse(new ApiProblem( | ||
400, | ||
'unrecognized method in X-HTTP-Method-Ovverride header' |
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.
U
in unrecognized
please
Attached listener depending on `x_http_method_override_enabled` Added $xHttpMethodOverrideEnabled to ContentNegotiationOptions (defaults to false);
Updated the PR:
|
@Wilt there is already existing module https://github.com/rstgroup/http-method-override |
@snapshotpl OK, thanks. |
<?php | ||
/** | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com) |
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.
Please use only 2016
year in new files.
@Wilt I like it, I think will be nice to have this functionality out-of-the-box. 👍 |
removed trailing comma removed space
@webimpress Thanks for the feedback. I changed to prophecy. I don't like the fact that the |
HttpRequest::METHOD_PATCH | ||
], | ||
HttpRequest::METHOD_POST => [ | ||
] |
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.
please add trailing comma
@Wilt do you mean your IDE doesn't recognize these methods? |
added php doc
Looks great. I think this should be baked into Apigility. |
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 is solid - thanks, @Wilt !
|
||
/** | ||
* Priority is set very high (should be executed before all other listeners that rely on the request method value). | ||
* TODO: Check priority value, maybe value should be even higher?? |
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 is an appropriate value. The OPTIONS handling (i.e., HTTP method negotiation) happens at -100. Currently, we already have versioning (for Accept headers) happening at -40 (route-based version checking happens at -41). The main thing is that it happens before the OPTIONS handling, so this works fine.
@@ -48,6 +48,11 @@ public function onBootstrap(MvcEvent $e) | |||
$services->get(AcceptFilterListener::class)->attach($eventManager); | |||
$services->get(ContentTypeFilterListener::class)->attach($eventManager); | |||
|
|||
$contentNegotiationOptions = $services->get(ContentNegotiationOptions::class); | |||
if ($contentNegotiationOptions->getXHttpMethodOverrideEnabled()) { | |||
$services->get(HttpMethodOverrideListener::class)->attach($eventManager); |
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 very much like this conditional attachment.
X-HTTP-Method-Override listener
Thanks, @Wilt! |
You are very welcome! |
X-HTTP-Method-Override listener feature.
For this issue: zfcampus/zf-apigility#175 (comment)