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

AuthServiceProvider contains unused method Policies() #26810

Closed
cthorne91 opened this issue Dec 12, 2018 · 2 comments
Closed

AuthServiceProvider contains unused method Policies() #26810

cthorne91 opened this issue Dec 12, 2018 · 2 comments

Comments

@cthorne91
Copy link

I was working on my AuthServiceProvider refactoring a large array assignment to the $policies property at the top of the file. I came across something that looked broken inside the framework's AuthServiceProvider, but I wanted to check with the community to see if I am overlooking something.

Long story short, overwriting the framework's AuthServiceProvider's public function policies() inside my own AuthServiceProvider never gets called and so has no purpose as far as I can see. I would love to be able to overwrite the policies() function and return an array based on some logic.

The framework's AuthServiceProvider's public function registerPolicies() accesses the protected $policies property directly instead of requesting the property through the policies() method.

Seems like it would make sense to update the following line 24 to $this->policies() as opposed to $this->policies? Hope I'm making sense.

/**
* Register the application's policies.
*
* @return void
*/
public function registerPolicies()
{
foreach ($this->policies as $key => $value) {
Gate::policy($key, $value);
}
}

/**
* Get the policies defined on the provider.
*
* @return array
*/
public function policies()
{
return $this->policies;
}

I just ended up assigning the $policies property inside my boot method to get around this for now.

@staudenmeir
Copy link
Contributor

The method was added as a public accessor for the protected $policies: 6d8e530

@driesvints
Copy link
Member

It's indeed just for fetching the property values if you need it.

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

No branches or pull requests

3 participants