cakephp / authorization

PSR7 Middleware for authorization
MIT License
76 stars 46 forks source link

Suggestion: narrowing the type of $resource #246

Closed asgraf closed 11 months ago

asgraf commented 1 year ago

Currently, the $resource variable is defined as a mixed type. The mixed type is an alias for string|int|float|bool|null|array|object|callable|resource. I'll frankly admit that I can't imagine a use-case in which $resource could take a value other than object Therefore, I suggest that we narrow down the type of $resource down to object (or even down to hypothetical \Authorization\Policy\ResourceInterface)

ravage84 commented 1 year ago

@asgraf thanks for the suggestion. If it's not too much work, please create a pull request with your poposed changes.

Let's see what these changes could mean. May be the current test coverage could point us to something, already.

markstory commented 12 months ago

I could see object being a reasonable narrowing. Having to implement an interface is not something we should be adding, as it creates a huge BC break with no actual value.

ndm2 commented 12 months ago

Couldn't that break all sorts of custom resolvers? I remember the talk around string resolvers, and support for it added explicitly somewhere.

markstory commented 12 months ago

Couldn't that break all sorts of custom resolvers? I remember the talk around string resolvers, and support for it added explicitly somewhere.

Yes, any constraint we try and put on mixed runs the chance of breaking someone's application. I don't see many practical use cases of the resource being null|resource but I bet there is someone out there using it.

dereuromark commented 11 months ago

Can we revisited for Cake6