-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Make array value cookies able to be sent. #11209
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
Inherit documentation from the interface where possible.
Add a new method to get a cookie value as a string. I considered changing how `getValue()` works but thought that had bigger compatibility implications. Instead I've modified the interface/implementation. Normally I would shy away from changing interfaces, but this is a very new class and the likelihood of there be user-space implementations is quite low. Refs #11208
Codecov Report
@@ Coverage Diff @@
## master #11209 +/- ##
============================================
+ Coverage 93.14% 93.15% +<.01%
- Complexity 12981 12983 +2
============================================
Files 437 437
Lines 33626 33630 +4
============================================
+ Hits 31321 31328 +7
+ Misses 2305 2302 -3
Continue to review full report at Codecov.
|
| * This will collapse any complex data in the cookie with json_encode() | ||
| * | ||
| * @return string | ||
| */ |
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 reason not to use __toString?
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.
Cookies have more properties than just the value. Wouldn't the string value of a cookie include the Secure, HttpOnly, Path and Domain bits?
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.
Yep, you're absolutely right! Disregard :)
| */ | ||
| public function getValue() | ||
| { | ||
| return $this->value; |
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 applied your fix and it correctly save the cookie now.
However when I read the cookie value, it continues to be in json format.
Can be correct to modify here like this?
return $this->_expand($this->value);But also when using ServerRequest->getCookie($cookie_name); it returns the cookie value in json format and it doesn't call Cookie->getValue().
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.
By setting
return $this->_expand($this->value);There are warnings in the EncryptedCookieMiddleware so it's more complicated than this 😅
Also if you have the EncryptedCookieMiddleware active it already return the value in array format without the need to modify getValue()
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 value of the cookie is the JSON data though when you're reading from a request. The cookie middleware adds more behavior to cookies though. I wouldn't recommend people store JSON data in plaintext cookies as its full of 💣
Add a new method to get a cookie value as a string. I considered changing how
getValue()works but thought that had bigger compatibility implications. Instead I've modified the interface/implementation. Normally I would shy away from changing interfaces, but this is a very new class and the likelihood of there be user-space implementations is quite low.Refs #11208