Skip to content
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

Simplify Cookie Class #4596

Merged
merged 1 commit into from
Apr 26, 2021
Merged

Conversation

mostafakhudair
Copy link
Contributor

@mostafakhudair mostafakhudair commented Apr 21, 2021

Since we use php min version 7.3, why not passing all cookie options to the constructor itself directly.
Removed Cookie::create while new Cookie do the same thing directly.
Renamed Cookie::getExpiresTimestamp to Cookie::getExpires to be short and refer to it's property,
Renamed Cookie::withExpiresAt to Cookie::withExpires to fit it's property and also it may return expired cookie.

I think this is last change to new Cookie class should be done before the upcoming release

@paulbalandan what do you think about this changes? is it keeps the interface "fluent"? Thanks in advance

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR title is for changing the Cookie constructor yet you clearly have two PRs here.

  1. I approve the simplification of the constructor call for the Cookie as that is leaning towards 7.3.
  2. Unless you can give me reason why convertExpiresTimestamp is no longer accessible via class, I cannot accept the removal of static.
  3. For the expires changes (which clearly misplaced here in this PR), I understand that you want to make things simple here but I'm on the side of making things "fluent" on the side of the developer using this API. For example, if I want to make an "expired" Cookie object, which would I choose as more fluent -- $cookie->withExpires(0) or $cookie->withExpired(). I believe even non-devs would choose the 2nd option as that is clearer. Another one is I want to get the expires string suitable for Set-Cookie headers. I would definitely want to use $cookie->getExpiresString() over $cookie->getExpires(false). The getExpiresTimestamp() on the other hand is a side effect of having getExpiresString() so as to differentiate the two expires getters. It will be clear that one gets the string expires while the other gets the integer value.
  4. I don't get why the tests on Array Access were removed when there's no changes to that in the class. By removing those tests I'm assuming that the Cookie, after this PR change, now allows mutability which is in contrast to its immutable nature.

system/Cookie/Cookie.php Outdated Show resolved Hide resolved
system/Cookie/Cookie.php Outdated Show resolved Hide resolved
system/Cookie/Cookie.php Show resolved Hide resolved
@mostafakhudair
Copy link
Contributor Author

Cookie::getExpiresString is still here and has not been removed.

@mostafakhudair mostafakhudair changed the title Use Cookie Constructor Directly Simplify Cookie Class Apr 21, 2021
@mostafakhudair mostafakhudair force-pushed the cookie branch 3 times, most recently from 50fa7ec to 036fdec Compare April 23, 2021 09:13
@MGatner
Copy link
Member

MGatner commented Apr 24, 2021

I assume this is yet another PR that will need to be resolved before release. Please prioritize this.

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you'll revert all changes to expires we can get this merged. Otherwise, I'm afraid that is a blocker for merge.

On a side note, I think I made a mistake with withExpiresAt($expires = 0) by setting a default value. This should not be the case. It should be only withExpiresAt($expires).

user_guide_src/source/libraries/cookies.rst Outdated Show resolved Hide resolved
user_guide_src/source/libraries/cookies.rst Outdated Show resolved Hide resolved
system/Cookie/CookieInterface.php Outdated Show resolved Hide resolved
@mostafakhudair mostafakhudair force-pushed the cookie branch 2 times, most recently from ebcb5ce to bdfc2a3 Compare April 25, 2021 17:41
@paulbalandan paulbalandan merged commit e1f0810 into codeigniter4:develop Apr 26, 2021
@paulbalandan
Copy link
Member

Thank you, @mostafakhudair

@mostafakhudair
Copy link
Contributor Author

@paulbalandan Many thanks to you for you'r professional review and your patience

@mostafakhudair mostafakhudair deleted the cookie branch April 26, 2021 14:20
@MGatner
Copy link
Member

MGatner commented Apr 27, 2021

Thanks all around! I think we are now finally cleared for release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants