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

[9.x] Add hasUser method to Guard contract #39167

Merged
merged 2 commits into from
Oct 12, 2021
Merged

[9.x] Add hasUser method to Guard contract #39167

merged 2 commits into from
Oct 12, 2021

Conversation

mpyw
Copy link
Contributor

@mpyw mpyw commented Oct 12, 2021

The following PR by @TBlindaruk has been previously rejected at v5.8.

However, we are now at a new stage with many changes, such as introducing Contract on Query Builder implementation. I decided that it would be ready to resubmit this PR now. It is useful in some situations that knowing whether user() causes side effects in advance.

Note that we don't have to add setProvider() and getProvider() because they are mainly for internal use.

Breaking Changes

  • All custom Guard without GuardHelpers should explicitly implement hasUser() from now on.
    • Most Guard implementation which uses property caching should return ! is_null($this->user)
    • Guard without any caches should always return false

- #24518 in this PR was added method `hasUser` to the GuardHelper trait. As for me it will be useful to have this method in the contract.
@driesvints
Copy link
Member

driesvints commented Oct 12, 2021

I think we can rename this to a more applicable method like checkSilently and then add that as an alias on the GuardHelpers trait.

I do have to say that ideally, I wish check didn't produce any side effects. But it's too much of a breaking change probably to change that now.

@mpyw
Copy link
Contributor Author

mpyw commented Oct 12, 2021

@taylorotwell Hi! Do you have any ideas about renaming hasUser()?

@taylorotwell taylorotwell merged commit 438eba7 into laravel:master Oct 12, 2021
@mpyw mpyw deleted the feat/9.x/gurad-contract-has-user branch October 12, 2021 15:47
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.

4 participants