-
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
feat: add IncomingRequest::is() method #6995
Conversation
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.
To be beautiful code.😄
system/HTTP/IncomingRequest.php
Outdated
return strtolower($this->getMethod()) === $value; | ||
} | ||
|
||
if ($value === 'json') { |
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.
Not sure if json
belong here. But if we will have it, why not also have ajax
? Basically the same story.
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'm fine to add ajax
.
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.
Added.
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.
We already have the isAJAX() method.
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.
Yes, we have, and as you may notice, we use it. IMO proposed is()
method would serve as a convenient shortcut, so I don't see a problem with another way of accessing the same method.
public function isMethod(string $method) : bool {}
public function isGet() : bool {}
public function isPost() : bool {}
// e.t.c.
|
What do you mean? Why is lowercase wrong way? |
Because "the default method name is in uppercase." |
I think @iRedds was pointing out that we only need this method because we are inconsistent with our case in the
I'm not sure the best approach here. I am not opposed to this helper method, but I also believe it should be unnecessary. |
The lowercase/uppercase "problem" was indeed created by PSR-7 compatibility. I don't see a way to resolve it without introducing quite a big BC break because, by default, everything is in lowercase now (and was the same way in CI3). |
It seems method names should be case-sensitive. The |
4f364b4
to
5848832
Compare
@iRedds Do you say that the standard HTTP method names are in uppercase? $ curl -X get https://www.w3.org/ -i
HTTP/2 400
server: cloudflare
date: Wed, 21 Dec 2022 08:40:47 GMT
content-type: text/html
content-length: 155
cf-ray: -
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html> |
I think case-sensitivity is in our favor. We don't need to adjust the case on the method return because |
Yes, the current The behavior should be fixed but it is a big BC break. So it is better that we wait for v5.0. @MGatner This |
I agree with this.
|
5848832
to
ce5e3ff
Compare
ce5e3ff
to
5963b26
Compare
Rebased and resolved, and all green! |
Added docs. |
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 do t feel great about it but I agree with the logic that landed here. Definitely we should fix all this in v5.
Also, we need to move away from our AJAX methods as they are less and less reliable; maybe in the future we can provide some different terms for the same concept.
@MGatner I'm not sure if this label was meant to be added to this PR, but if so, I would have second thoughts about this PR. v5 means that we already have the Then, I would rather add the |
@michalsn I've been using that label for PRs or threads I want to come back and review for v5 content. It doesn't necessarily mean "this PR belongs in v5" (though sometimes) but more like "read this thread for a relevant v5 idea". |
Rector not to delete the code.
Co-authored-by: Pooya Parsa Dadashi <pooya_parsa_dadashi@yahoo.com>
5111dce
to
08e9377
Compare
Rebased and pushed two commits. |
We need the same method in CLIRequest because Controller can be run via CLI.
I found And it was removed in 4.1.2. Ah, it was added in 4.0.5. |
Well... it's strange to me why we deprecated |
I think |
Description
Writing code like
strtolower($this->request->getMethod()) !== 'post'
is a pain.IncomingRequest::is()
Checklist: