-
Notifications
You must be signed in to change notification settings - Fork 9.4k
MAX_NUM_COOKIES
doesn't follow the open-closed principle
#14109
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
Comments
Open-closed principle does not dictate |
This value is not supposed to be changed as it is based on RFC. Could you please describe what you try to achieve by changing this value? I remember it was a problem in
|
The open-close rule does not dictate anything. It’s a principle in which you don’t have to edit the original code to change the outcome. Binding to the constant using the static binding would achieve this. The static binding I’m talking about was referencing a constant. What I’m trying to achieve by changing the MAX_NUM_COOKIES constant is changing the max number of cookies. Logging error is cool, but I’m trying to mitigate it all together. Also, the RFC standards are 50, however, that's fairly conservative and most browsers tend to support a much higher limit. |
I meant that following this approach means to forbid Thanks for a really illustrative link! Looks like as Magento supports IE11
Great, looks like you really understand what you're doing 👍 If some Magento merchants don't care about IE and somehow their instance creates quite a bunch of cookies, value should be good to raise. Class inheritance is not a recommended way and bla-bla-bla but a better way than copy-paste and I don't think this parameter should be injected via constructor, so, Could you please create a pull request containing suggested change? For the future, when you desire a code change it can be posted directly as a PR, even if will be rejected or seriously reworked later it will be faster than discuss potential code change in an issue. |
I see, I personally always try to use Yeah, I did think about suggesting di or a config path, however, I don't know if you want it to be that easily configurable for reasons you've mentioned. I have created a pull request: I'm not sure whether I'm doing the correct thing in the test by referencing the constant from the object, I guess you could do a get_class or use class reflection but this seemed the simplest. Let me know if you want to update anything. |
@brideo, thank you for your report. |
Hi @brideo. Thank you for your report. The fix will be available with the upcoming 2.3.0 release. |
@brideo, could you possibly give an example of how to override MAX_NUM_COOKIES? I've tried overriding Magento\Framework\Stdlib\Cookie\PhpCookieManager::checkAbilityToSendCookie with Preference but no luck. |
Hey @siliconalchemy, I assume the class is still the same so you will need to add a preference to your class then override the max cookie constant.
Output:
|
Hey @brideo, thanks for response. Is it not possible to override the core class to reset MAX_NUM_COOKIES?
This has no effect as a preference (setting to 2 to test). |
Preconditions
Steps to reproduce
PhpCookieManager::MAX_NUM_COOKIES
Expected result
static::MAX_NUM_COOKIES
Actual result
The text was updated successfully, but these errors were encountered: