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

[10.x] Register policies automatically to the gate #46132

Merged
merged 3 commits into from
Feb 16, 2023

Conversation

ahmett
Copy link
Contributor

@ahmett ahmett commented Feb 15, 2023

This PR aims to enhance eventual consistency between parts of the framework.

Unlike the other features of the framework (observers, listeners, etc.), policies don't get automatically registered while AuthServiceProvider is booting. It is required to call the registerPolicies method.

And I think this is redundant.

Logic preserves its natural behavior. It doesn't affect auto-discovery, defined with the Gate::guessPolicyNamesUsing method.

I also create a PR in the skeleton repo to remove redundant calling of the registerPolicies method.

@ahmett
Copy link
Contributor Author

ahmett commented Feb 15, 2023

Docs updated according to this PR, see: laravel/docs#8584
Skeleton repo also updated, see: laravel/laravel#6108

@taylorotwell
Copy link
Member

Won't they be registered twice if we make this change and people don't update their skeleton?

@ahmett
Copy link
Contributor Author

ahmett commented Feb 15, 2023

@taylorotwell It won't because we are replacing that method. Existing codebases with 10.x only need to delete that method call from the service provider. I already documented this in upgrade docs.

Edit: We also could re-add the registerPolicies method with an empty body to preserve compatibility with 10.x codebases whose doesn't delete that method call. This makes deleting the method call optional.

Example:

/**
  * It's unused and does nothing, if you are calling this method you can safely delete the method call.
  *
  * @deprecated Will be removed in a future Laravel version.
  */
public function registerPolicies(): void {}

@taylorotwell taylorotwell merged commit 66ce77d into laravel:10.x Feb 16, 2023
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.

2 participants